Instead Of IntroI am a .NET developer who has recently moved to front-end realms.Unit testing was never a strong side of mine, but what I learnt is that the test code has to be of highest quality possible (follow DRY, SOLID, etc).Otherwise, the code faces rapidly increasing risk of rotting since test maintenance becomes burdensome.Not having experience with JavaScript/Jasmine makes me write C#-ish code in real system and tests.Getting some feedback should help in long run with keeping project in a good shape.CodeClass under test (Spectra) declares several methods which are made public for now.Each method is essentially a pure function, so it's really easy to test each of them independently.export class Spectra {  public static numberInRangeToRgb(value: number, min: number, max: number): string { ... }  public static waveLengthFromDataPoint(value: number, minValue: number, maxValue: number): number { ... }  public static waveLengthToRGB(waveLengthInNanoMeters: number): number[] { ... }  public static rgbFromWaveLength(waveLengthInNanoMeters: number): number[] { ... }  public static factorFromWaveLength(waveLengthInNanoMeters: number): number { ... }  public static adjust(color: number, factor: number): number { ... }}Here are the unit tests I've written so far.describe('Spectra', () => {  function title(testCase: any): string {    return `works for ${JSON.stringify(testCase)} test case`;  }  describe('numberInRangeToRgb', () => {    [      { value: 0, min: 0, max: 10, expectedResult: '#000000' },      { value: 5, min: 0, max: 10, expectedResult: '#00ff92' },      { value: 10, min: 0, max: 10, expectedResult: '#ff0000' },      { value: 0, min: -10, max: 0, expectedResult: '#ff0000' },      // More cases    ].forEach(testCase => {      it(title(testCase), () => {        const { value, min, max, expectedResult } = testCase;        expect(Spectra.numberInRangeToRgb(value, min, max)).toEqual(expectedResult);      });    });  });  describe('waveLengthFromDataPoint', () => {    [      { value: 10, min: 10, max: 20, expectedResult: 350 },      // More cases    ].forEach(testCase => {      it(title(testCase), () => {        const { value, min, max, expectedResult } = testCase;        expect(Spectra.waveLengthFromDataPoint(value, min, max)).toBeCloseTo(expectedResult);      });    });  });  describe('waveLengthToRGB', () => {    [      { waveLength: 300, expectedResult: [0, 0, 0] },      // More cases    ].forEach(testCase => {      it(title(testCase), () => {        const { waveLength, expectedResult } = testCase;        expect(Spectra.waveLengthToRGB(waveLength)).toEqual(expectedResult);      });    });  });  describe('rgbFromWaveLength', () => {    [      { waveLength: -100, expectedResult: [0, 0, 0] },      // More cases    ].forEach(testCase => {      it(title(testCase), () => {        const { waveLength, expectedResult } = testCase;        expect(Spectra.rgbFromWaveLength(waveLength)).toEqual(expectedResult);      });    });  });  describe('factorFromWaveLength', () => {    [      { waveLength: -100, expectedFactor: 0 },      // More cases    ].forEach(testCase => {      it(title(testCase), () => {        const { waveLength, expectedFactor } = testCase;        expect(Spectra.factorFromWaveLength(waveLength)).toBeCloseTo(expectedFactor);      });    });  });  describe('adjust', () => {    [      { color: 1, factor: 2, expectedResult: 444 },      // More cases    ].forEach(testCase => {      it(title(testCase), () => {        const { color, factor, expectedResult } = testCase;        expect(Spectra.adjust(color, factor)).toBe(expectedResult);      });    });  });});Code Review FocusI would really appreciate constructive feedback on:Whether I miss anything in terms of JavaScript/TypeScript idioms.Same about Jasmine idioms, techniques, approaches.General code improvements.Test differentiation/separation techniques (some are real unit-tests, other are more of integration tests).Update 1 - Test ResultsThis is what Karma test runner will produce as a result of the test suite run, by the way.
Jasmine tests for TypeScript class's pure functions
javascript;unit testing;typescript;jasmine