Jasmine spyOn with specific arguments
You can use callFake: spyOn($cookieStore,’get’).and.callFake(function(arg) { if (arg === ‘someValue’){ return ‘someabc’; } else if(arg === ‘anotherValue’) { return ‘anotherabc’; } });
You can use callFake: spyOn($cookieStore,’get’).and.callFake(function(arg) { if (arg === ‘someValue’){ return ‘someabc’; } else if(arg === ‘anotherValue’) { return ‘anotherabc’; } });
Just tested this and it works: element(by.css(‘[ng-click=”myFunction()”]’))
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
The difference is that you should have a method on the object with spyOn const o = { some(): { console.log(‘spied’) } }; spyOn(o, ‘some’); while the mock method is created for your with createSpy(): const o = {}; o.some = jasmine.createSpy(‘some’); The advantage of the spyOn is that you can call the original method: … Read more
Sure, you just call beforeEach() without any spec scoping at all, and add matchers there. This would globally add a toBeOfType matcher. beforeEach(function() { var matchers = { toBeOfType: function(typeString) { return typeof this.actual == typeString; } }; this.addMatchers(matchers); }); describe(‘Thing’, function() { // matchers available here. }); I’ve made a file named spec_helper.js full … Read more
From this thread: console.log(expect.getState().currentTestName); Worked for me.
You can declare disabled functions in both mocha and jasmine using xit (instead of it), and xdescribe (instead of describe). If you want the tests to appear as pending, in mocha you can just leave the second parameter blank in the call to the it() function. For example: describe(‘Something’, function () { it(‘Should be pending’) … Read more
After doing some digging, I’ve discovered that Jasmine spy objects have a calls property, which in turn has a mostRecent() function. This function also has a child property args, which returns an array of call arguments. Thus, one may use the following sequence to perform a regexp match on call arguments, when one wants to … Read more
Depending on what you want to do, you can try: browser.waitForAngular(); or btnLoginEl.click().then(function() { // do some stuff }); to solve the promise. It would be better if you can do that in the beforeEach. NB: I noticed that the expect() waits for the promise inside (i.e. getCurrentUrl) to be solved before comparing.
You can use predefined JS library stubs in Webstorm/PHPStorm/Idea Open File > Settings… Select Languages & Frameworks > JavaScript > Libraries Click on Download… Swich to TypeScript community stubs Find karma-jasmine (originally under the name jasmine) (If this does not work, try jasmine instead) Click on Download and Install I am using this setup with … Read more