Consider the following tests (in Jasmine), where the first is synchronous and the second is asynchronous:
describe("The system", function() {
it("should fail", function() {
expect(true).toBe(false);
});
it("should succeed", function(done) {
setTimeout(function() {
expect(1).toBe(1);
done();
}, 10);
});
});
Uncaught Expected true to be false.
at UserContext.<anonymous> (http://localhost:9876/base/test.spec.js:4:22) thrown
karma --version): 1.7.0karma.config.js file is default out of the box, configured to load '*.js' files.npm initnpm install karma karma-jasmine jasmine-core karma-chrome-launcher --save-devtest.spec.js and add the test code that is listed above.karma init and accept all defaults. Enter *.js and *.spec.js as files location."test": "karma start" to the package.json scripts section.npm run testDebug button to open the Karma DEBUG RUNNER.@daanstolp I think this has resurfaced. Using Angular CLI 6.0.6 (karam ^2.0.4).
@dignifiedquire
If a component throws an error (in our case we have a validator that throws an error if it's used incorrectly), the next test will fail. Running the tests in isolation will return a success.
In our case, we have a custom validator that matches two fields, but if the selected field does not exist the validator with throw an error. This causes the next it() test to fail.
@michael-letcher I'm encountering this with such code:
spyOn(service, 'uploadFile').and.returnValue(throwError(Error()));
If I test in isolation, it works, if I run all tests, the second one fails.
Also, if I use DoneFn and I call it, the test including the spyOn fails
Most helpful comment
@daanstolp I think this has resurfaced. Using Angular CLI 6.0.6 (karam ^2.0.4).
@dignifiedquire
If a component throws an error (in our case we have a validator that throws an error if it's used incorrectly), the next test will fail. Running the tests in isolation will return a success.
In our case, we have a custom validator that matches two fields, but if the selected field does not exist the validator with throw an error. This causes the next it() test to fail.