-
Notifications
You must be signed in to change notification settings - Fork 18
Testing using Jasmine
erikvullings edited this page Dec 15, 2014
·
1 revision
csCompTests is a separate project that is used to test the csComp library. It:
- Uses gulp to copy the generated csComp.js en csComp.d.ts files to the csCompTests/csComp folder.
- Is build to a single file, named specifications.js
- Loads the jasmine files and other dependencies like angular, csComp.js and specification.js in index.html, and runs the tests in there.
As stated above, just open csCompTests/index.html in your browser, and all tests will be run.
This should be quite simple.
- Create a new specificationXXX.ts file, where XXX is the name of the model or module you wish to test.
- Add test code to it. For an example, see below.
describe('The MCA model ', () => {
beforeEach(() => {
this.mca = new Mca.Models.Mca();
this.mca.criteria.push({ userWeight: 5, criteria: [] });
this.mca.criteria.push({ userWeight: 3, criteria: [] });
this.mca.criteria.push({ userWeight: 2, criteria: [] });
});
it('should calculate the correct weights based on the user weights.', () => {
this.mca.calculateWeights();
expect(this.mca.criteria[0].weight).toBe(0.5);
expect(this.mca.criteria[1].weight).toBe(0.3);
expect(this.mca.criteria[2].weight).toBe(0.2);
});
it('should assign a color to each criterion after updating.', () => {
expect(this.mca.criteria[0].color != null).toBe(false);
expect(this.mca.criteria[1].color != null).toBe(false);
expect(this.mca.criteria[2].color != null).toBe(false);
this.mca.update();
expect(this.mca.criteria[0].color != null).toBe(true);
expect(this.mca.criteria[1].color != null).toBe(true);
expect(this.mca.criteria[2].color != null).toBe(true);
});
});