how to fix Error: ASSERTION ERROR: Should be run in update mode [Expected=> false == true
I got it all working, I have placed the function getVersionInfos in the ngOnInit instead of inside the constructor
I got it all working, I have placed the function getVersionInfos in the ngOnInit instead of inside the constructor
You can know the jasmine version you are using by running the following Spec: describe(‘Test to print out jasmine version’, function() { it(‘prints jasmine version’, function() { console.log(‘jasmine-version:’); console.log(jasmine.version || (jasmine.getEnv().versionString && jasmine.getEnv().versionString())); }); }); and then checking the karma output in your console or browser. It should be something like: LOG: ‘jasmine-version:’ LOG: ‘2.3.4’ … Read more
Preventing lifecycle hook (ngOnInit) from being called is a wrong direction. The problem has two possible causes. Either the test isn’t isolated enough, or testing strategy is wrong. Angular guide is quite specific and opinionated on test isolation: However, it’s often more productive to explore the inner logic of application classes with isolated unit tests … Read more
You need this for version rxjs@6 and above. For older rxjs version answer is below: import { of } from ‘rxjs’; it(“should call getUsers and return list of users”, async(() => { const response: User[] = []; spyOn(userService, ‘getUsers’).and.returnValue(of(response)) homeComponent.getUsers(); fixture.detectChanges(); expect(homeComponent.listOfUsers).toEqual(response); })); For old rxjs version change import from: import { of } from … Read more
If the element is hidden, then it wont be rendered inside the dom. You can check expect(fixture.debugElement.query(By.css(‘.header’))).toBeUndefined(); EDIT : toBeNull() works better in the above case expect(fixture.debugElement.query(By.css(‘.header’))).toBeNull(); And also you have a syntax error while fetching the button element. nativeElement is not a function. Change it this way : const button = fixture.debugElement.query(By.css(‘button’)).nativeElement;
I had the same problem and tried a lot of the suggested solutions I found, but what finally solved it for me was to delete the node_modules folder and getting everything new via npm install.
What is happening: The function itemToForm() is being called before the this.item is ready. There are many strategies to avoid this error. A very simple one is to add a catcher at the beginning of the function, like this: itemToForm = () => { if(this.item === undefined) {return} // The rest of the code } … Read more
You can use several techniques here: karma uses minimatch globs for file paths and use can take advantage of that to exclude some paths. As first solution I’d say try to add only the paths of the file to preprocess with the coverage: // karma.conf.js module.exports = function(config) { config.set({ files: [ ‘src/**/*.js’, ‘test/**/*.js’ ], … Read more
undefined is not a constructor is an error message PhantomJS displays when you tried to call a function that is not defined. It depends on the version of ECMAScript which your PhantomJS supports. So as you said it works fine in Chrome, because this browser supports the function you are using in test. In order … Read more
Guess I’m a little late to the party, However this may be useful to some one in the future. There have been a few changes to testing since RC 5 of angular has been released. However the main issue over here is ngOnChanges is not called when inputs are set programmatically. See this for more … Read more