jasmine

Error while integrating html with testacularjs

馋奶兔 提交于 2019-12-03 13:07:37
How do I integrate (html) fixtures with testacular? Is there any recommendation for performing DOM based tests or is it an anti-pattern? Objective : I am trying to test a custom module which parses the DOM tree and creates a new data structure. The DOM tree can be dynamic (like contents of a html/markdown editor) and hence is not a good candidate for end to end testing Problem : I am trying to use jasmine-jquery for this DOM testing and in my testacular.conf.js, I have the section to allow loading of html files into the browser. // list of files / patterns to load in the browser files = [

Jasmine can't spy on event handler?

百般思念 提交于 2019-12-03 12:49:47
Trying to test that an event handler gets called on a clicked element with Jasmine. Have a "Pad" object that contains a DOM element "PadElement", which gets clicked. The event handler is a method on the Pad object: GRAPH.Pad = function(graphDiv, graph) { this.graph = graph; this.clickHandler = function(e) { console.log('padElement clickHandler called'); //this.graph.createVertex(e.clientX, e.clientY); }; this.padElement = GRAPH.padElement(graphDiv, this.clickHandler); } GRAPH.padElement = function(graphDiv, clickHandler) { //Initialize pad var NS="http://www.w3.org/2000/svg"; var pad=document

Spying on Backbone.js route calls with Jasmine

夙愿已清 提交于 2019-12-03 12:42:37
问题 Having problems spying method calls on a Backbone Router to ensure it calles the right method on a given route. excerpt from the test describe 'Router', -> beforeEach -> @router = new App.Router() Backbone.history.start() afterEach -> Backbone.history.stop() describe 'routes', -> it 'should be defined', -> expect(@router.routes).toBeDefined() describe 'default route', -> it 'should be defined', -> expect(@router.routes['']).toBeDefined() it 'should call index', -> spy = spyOn(@router, "index"

Jasmine/Protractor: stop test on failure in beforeEach

对着背影说爱祢 提交于 2019-12-03 12:26:45
I am currently writing tests protractor and I was wondering if there is some possibility to cancel test execution as soon as something in the beforeEach fails (and return some useful message like "precondition failed: could not login user"). I.e. I have some helper methods in the beforeEach that login the user and then do some setup. beforeEach: 1) login user 2) set some user properties Obviously it does not make any sense to execute the 2nd step if the first one fails (actually its quite harmful as the user gets locked which is not nice). I tried to add an "expect" as part of the 1st step,

Branches on constructor not covered

我是研究僧i 提交于 2019-12-03 12:25:31
I am creating my unit tests with Jasmine and I have a question about the branch covered. Does anyone know why the code part shows that the branches are not covered as we can see below? This is the unit test: describe('MyComponent', () => { let component: MyComponent; let fixture: ComponentFixture<MyComponent>; let myService: MyService; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ MyComponent ], imports: [ MaterializeModule, FormsModule, ReactiveFormsModule, HttpModule ], providers: [ MyService, FormBuilder ] }) .compileComponents(); })); beforeEach(() => { fixture

$scopeProvider <- $scope/ Unknown provider

99封情书 提交于 2019-12-03 12:08:07
问题 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(

Test login with protractor on a non angular page

我只是一个虾纸丫 提交于 2019-12-03 12:02:10
I am trying to use protractor for e2e testing but first I need to login on a non-angular page. I try to directly use the webDriver as indicated here but it fails. My e2e test: describe('angularjs homepage', function() { it('should prompt the login page', function() { browser.get('/'); expect(browser.driver.find(By.id('user_password'))); }); }); My logs: Running "protractor:all" (protractor) task Using the selenium server at http://localhost:4444/wd/hub F Failures: 1) angularjs homepage should prompt the login page Message: TypeError: Object [object Object] has no method 'find' Do you know a

Testing javascript with Chutzpah and requirejs

百般思念 提交于 2019-12-03 11:36:17
I just wonder if there is a simple tutorial showing how to test javascript in visual studio with Chutzpah, require.js and jasmine. Basically, i want to run the tests without using an .html file so that i can see the results in the vs test explorer. Adamy You can find some sample codes here: https://chutzpah.codeplex.com/SourceControl/latest#Samples/RequireJS/Jasmine/tests/base/base.jasmine.test.js Please note if you want to use requirejs with Chutzpah and Jasmine, you need to set TestHarnessReferenceMode to AMD in chutzpah.json. Otherwise the tests won't be ran in browser. { "Framework":

Angular 2 - test for change in route params

被刻印的时光 ゝ 提交于 2019-12-03 11:33:59
问题 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

How to mock AngularFire 2 service in unit test?

纵饮孤独 提交于 2019-12-03 11:33:56
问题 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 =