jasmine

Typescript 2.0. “types” field in tsconfig.json

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I do not understand the meaning of types field in tsconfig.json . In documentation I have read such text: "types": { "description": "Type declaration files to be included in compilation. Requires TypeScript version 2.0 or later.", "type": "array", "items": { "type": "string" } }, As far, as I understand if I install @types/express I should add such string in tsconfig.json { "compilerOptions": { ... "types": ["lodash"] } } but everything works fine without it. And now I do not understand, why I need types field 回答1: As of TypeScript 2.* the

How to mock AngularFire 2 service in unit test?

夙愿已清 提交于 2019-12-03 02:09:35
I'm trying to set up unit tests for a sample Angular 2 app using AngularFire 2 auth, the component is fairly simple: import { Component } from '@angular/core'; import { AngularFire, AuthProviders } from 'angularfire2'; @Component({ moduleId: module.id, selector: 'app-root', templateUrl: 'app.component.html', styleUrls: ['app.component.css'] }) export class AppComponent { isLoggedIn: boolean; constructor(public af: AngularFire) { this.af.auth.subscribe(auth => { if (auth) { this.isLoggedIn = true; } else { this.isLoggedIn = false; } }); } loginWithFacebook() { this.af.auth.login({ provider:

jasmine 2 - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL

匿名 (未验证) 提交于 2019-12-03 02:07:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Having trouble with jasmine 2 and getting async specs wired up: define(['foo'], function(foo) { return describe('foo', function() { beforeEach(function(done) { window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; return setTimeout((function() { console.log('inside timeout'); return done(); }), window.jasmine.DEFAULT_TIMEOUT_INTERVAL); }); return it('passes', function() { return expect({}).toBeDefined(); }); }); }); When I run via karma, I get back Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT

How to run Jasmine tests on Node.js from command line

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I run Jasmine tests on Node.js from command line? I have installed jasmine-node via npm and written some tests. I want to run tests inside the spec directory and get results in the terminal, is this possible? 回答1: EDIT It seems this is no longer the current best answer as the package is unmaintained. Please see the answer below You can do this from your test directory sudo npm install jasmine-node This installs jasmine into ../node_modules/jasmine-node then ../node_modules/jasmine-node/bin/jasmine-node --verbose --junitreport -

Angular 2 - test for change in route params

一笑奈何 提交于 2019-12-03 01:57:41
I have a component in angular 2 which responds to changes in the route parameters (the component doesn't reload from scratch because we're not moving out of the main route. Here's the component code: export class MyComponent{ ngOnInit() { this._routeInfo.params.forEach((params: Params) => { if (params['area']){ this._pageToShow =params['area']; } }); } } This works a treat and _pageToShow is set appropriate on navigation. I'm trying to test the behaviour on a change to the route (so a second trigger of the observable but it's refusing to work for me.) Here's my attempt: it('sets PageToShow to

Testing routers in backbone.js properly?

点点圈 提交于 2019-12-03 01:56:52
问题 So I've just started to write tests for my in-progress javascript app, using sinon.js & jasmine.js . Works pretty well overall, but I need to also be able to test my routers. The routers, in their current state, will trigger an number of views and other stuff, terminating the current jasmine.js test by invoking Backbone.navigate dependent on application state and UI itneraction. So how could I test that routing to different locations would work, while keeping the routers "sandboxed" and not

$scopeProvider <- $scope/ Unknown provider

妖精的绣舞 提交于 2019-12-03 01:42:42
I testing my angular-application with jasmine( http://jasmine.github.io/2.0/ ) and getting next error: Unknown provider: $scopeProvider <- $scope I know, that it's incorrect to build dependency with scope in filters, services, factories, etc., but I use $scope in controller! Why am i getting this error? controller looks like testModule.controller('TestCont', ['$filter', '$scope', function($filter, $scope){ var doPrivateShit = function(){ console.log(10); }; this.lol = function(){ doPrivateShit(); }; this.add = function(a, b){ return a+b; }; this.upper = function(a){ return $filter('uppercase')

How to expect an asynchronously thrown exception in Jasmine / Angular2 / Typescript?

匿名 (未验证) 提交于 2019-12-03 01:41:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Given an Angular2/Typescript method that returns nothing and implements a .subscribe() handler which might throw, such as this: onSubmit () { // returns nothing this . service . someCall ( this . someData ). subscribe ( data => { return Promise . reject ( 'This is an asynchronously thrown error.' ); }, err => {}, ); } (For the moment, let's assume that there's a good reason for this .subscribe() handler to (probably conditionally) reject without other testable side-effects, thus resulting only in an error message bubbling up to the

Jasmine/PhantomJs spec runner

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I cannot get my test to run using phantomJs. gulp task var jasminePhantomJs = require ( 'gulp-jasmine2-phantomjs' ); gulp . task ( 'test' , function () { return gulp . src ( './SpecRunner.html' ) . pipe ( jasminePhantomJs ()); }); SpecRunner.html <script src = "lib/jquery.min.js" ></script> <script src = "lib/lodash.min.js" ></script> <script type = "text/javascript" src = "lib/jasmine-2.0.0/jasmine.js" ></script> <script type = "text/javascript" src = "lib/jasmine-2.0.0/jasmine-html.js" ></script> <script type = "text/javascript"

Mocking router.events.subscribe() Angular2

不问归期 提交于 2019-12-03 01:36:11
In my app.component.ts I have the following ngOnInit function: ngOnInit() { this.sub = this.router.events.subscribe(e => { if (e instanceof NavigationEnd) { if (!e.url.includes('login')) { this.loggedIn = true; } else { this.loggedIn = false; } } }); } Currently I'm testing if the sub is not null but I want to test the function with a 100% coverage. I want to mock the router object so that I can simulate the URL and then test if the this.loggedIn is correctly set. How would I proceed to mock this function? I tried it but I don't know how I would take this on with the callback involved and with