Angular 2 Unit Tests: Cannot find name ‘describe’

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

How to access and test an internal (non-exports) function in a node.js module?

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

toBe(true) vs toBeTruthy() vs toBeTrue()

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 to write unit testing for Angular / TypeScript for private methods with Jasmine

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

How can I write a test which expects an ‘Error’ to be thrown in Jasmine?

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