Jasmine.js comparing arrays
Is there a way in jasmine.js to check if two arrays are equal, for example: arr = [1, 2, 3] expect(arr).toBe([1, 2, 3]) expect(arr).toEqual([1, 2, 3]) Neither seems to work. 4 Answers 4
Is there a way in jasmine.js to check if two arrays are equal, for example: arr = [1, 2, 3] expect(arr).toBe([1, 2, 3]) expect(arr).toEqual([1, 2, 3]) Neither seems to work. 4 Answers 4
Is there a way to run ng test for a single file instead of for the entire test suite? Ideally, I’d like to get the quickest possible feedback loop when I’m editing a file, but karma executes the whole suite on each save, which is a bit slow when you build up a big enough … Read more
I have Angular2 project build with Angular-CLI (beta 20). Is there a way to run tests against only one selected spec file? I used to have a project based on Angular2 quick start, and I could manually add specs to jasmine file. But I don’t know how to set this up outside of karma testing … Read more
I’m following this tutorial from angular.io As they said, I’ve created hero.spec.ts file to create unit tests: import { Hero } from ‘./hero’; describe(‘Hero’, () => { it(‘has name’, () => { let hero: Hero = {id: 1, name: ‘Super Cat’}; expect(hero.name).toEqual(‘Super Cat’); }); it(‘has id’, () => { let hero: Hero = {id: 1, … Read more
I’m trying to figure out on how to test internal (i.e. not exported) functions in nodejs (preferably with mocha or jasmine). And i have no idea! Let say I have a module like that: function exported(i) { return notExported(i) + 1; } function notExported(i) { return i*2; } exports.exported = exported; And the following test … Read more
What is the difference between expect(something).toBe(true), expect(something).toBeTruthy() and expect(something).toBeTrue()? Note that toBeTrue() is a custom matcher introduced in jasmine-matchers among other useful and handy matchers like toHaveMethod() or toBeArrayOfStrings(). The question is meant to be generic, but, as a real-world example, I’m testing that an element is displayed in protractor. Which matcher should I use … Read more
How do you test a private function in angular 2 ? class FooBar { private _status: number; constructor( private foo : Bar ) { this.initFooBar(); } private initFooBar(){ this.foo.bar( “data” ); this._status = this.fooo.foo(); } public get status(){ return this._status; } } The solution I found Put the test code itself inside the closure or … Read more
Let’s say I have the following: var myNumber = 5; expect(myNumber).toBe(5); expect(myNumber).toEqual(5); Both of the above tests will pass. Is there a difference between toBe() and toEqual() when it comes to evaluating numbers? If so, when I should use one and not the other? 7 Answers 7
I’m trying to write a test for the Jasmine Test Framework which expects an error. At the moment I’m using a Jasmine Node.js integration from GitHub. In my Node.js module I have the following code: throw new Error(“Parsing is not possible”); Now I try to write a test which expects this error: describe(‘my suite…’, function() … Read more