jasmine

QUnit vs Jasmine? [closed]

爷,独闯天下 提交于 2019-12-02 16:32:59
What are the main differences between these two testing frameworks? I am a totally new to Test Driven Development and starting from the very beginning. QUnit is very easy to get started with, as you only need to include two files and a little bit of markup, then you can start writing tests. Jasmine strength, afaik is its BDD-style syntax, if that is something that you prefer (probably not a selling point for you) and tight integration into Ruby/Rails tools. In the end both get the job done. I recommend to start with QUnit. Once you're feeling comfortable, try Jasmine and check if the BDD style

Jasmine vs. Mocha JavaScript testing for Rails 3.1+ [closed]

旧巷老猫 提交于 2019-12-02 16:20:10
I have experience with Jasmine and do like it quite a bit. Does anyone have experience with both Jasmine and Mocha, specifically for Rails? I am wondering if it's worth switching to. I have done testing in both Jasmine and Mocha. First, switching is relatively easy. The basic describe and it BDD pattern is identical. You will need to change how you do your assertions and switch to a different interface for asynchronous tests. Overall they are comparable. Mocha's asynchronous interface is much simpler and more consistent. Tests and setup can be either synchronous or asynchronous, which is great

mock object for document element

坚强是说给别人听的谎言 提交于 2019-12-02 15:48:49
I have next test code: it("Test", function() { loadResources(); expect(document.getElementById('MyElement').innerHTML).toBe("my string"); }); Body of function loadResources() : document.getElementById('MyElement').innerHTML = "my string"; My test fails with following message: TypeError: Cannot set property "innerHTML" of null. Looks like I need to create mock object for innerHTML. How I can do it? I think you should mock getElementById to return a dummy HTMLElement JASMINE V1.3 OR BELOW var dummyElement = document.createElement('div'); document.getElementById = jasmine.createSpy('HTML Element'

Testing routers in backbone.js properly?

偶尔善良 提交于 2019-12-02 15:33:35
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 allowing them to change route? Can I set up some sort of mock function that will monitor pushState

Angular2 testing: What's the difference between a DebugElement and a NativeElement object in a ComponentFixture?

六月ゝ 毕业季﹏ 提交于 2019-12-02 15:04:16
I'm currently putting together some best practices for testing Angular 2 apps on a component level. I've seen a few tutorials query a fixture's NativeElement object for selectors and the like, e.g. it('should render "Hello World!" after click', async(() => { builder.createAsync(HelloWorld).then((fixture: ComponentFixture<HelloWorld>) => { fixture.detectChanges(); let el = fixture.nativeElement; el.querySelector('h1').click(); fixture.detectChanges(); expect(el.querySelector('h1')).toHaveText('Hello World!'); }); })); However, in juliemr's Angular 2 test seed she accesses the NativeElement

Load local JSON into Jasmine/Karma Unit Test in AngularJS

你。 提交于 2019-12-02 14:11:42
问题 I'm testing a callback function which accepts a response object as it's only parameter. This object is the response of a HTTP request made elsewhere so I don't want to user $httpBackend in this test as the request has nothing to do with this function. It's in home.js which is a controller for the homepage of my app. Here is the function being tested: function submitLogin() { LoginService.login(loginPost, ctrl.username, ctrl.password, successCallback, errorCallback); } // gets called in

Frontend testing: what and how to test, and what tool to use?

和自甴很熟 提交于 2019-12-02 14:04:20
I have been writing tests for my Ruby code for a while, but as a frontend developer I am obviously interested in bring this into the code I write for my frontend code. There is quite a few different options which I have been playing around with: CasperJS Capybara & Rspec Jasmine Cucumber or just Rspec What are people using for testing? And further than that what do people test? Just JavaScript? Links? Forms? Hardcoded content? Any thoughts would be greatly appreciated. Carlos I had the same questions a few months ago and, after talking to many developers and doing a lot of research, this is

Expected Response with status: null null for URL: null to equal 'Project11'

≡放荡痞女 提交于 2019-12-02 13:59:24
I am using angular7 and doing unit testing in jasmine and karma. And I am facing error - Error: Expected Response with status: null null for URL: null to equal 'Project11'. My packages versions are - "@types/jasmine": "~2.8.6", "@types/jasminewd2": "~2.0.3", "@types/jquery": "^3.3.22", "@types/node": "~8.9.4", "codelyzer": "~4.2.1", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~1.7.1", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~1.4.2", "karma-jasmine": "~1.1.1", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "^5.4.1", "ts-node":

Test for rejected promise with Jasmine

ⅰ亾dé卋堺 提交于 2019-12-02 12:43:56
In my Angular2 app which uses AngularFire2, I have an AuthService which tries to authenticate anonymously with Firebase. I am trying to write a test that expects AngularFireAuth 's signInAnonymously to return a rejected promise; for authState to be null and an error to be thrown. I an new to Jasmine and testing in general but I think I may need to be using asynchronous tests but I'm getting quite stuck. Here is a simplified AuthService : import { Injectable } from '@angular/core'; import { AngularFireAuth } from 'angularfire2/auth'; import * as firebase from 'firebase/app'; import { Observable

Angular: How to spy on $element.on

旧时模样 提交于 2019-12-02 10:38:02
问题 I have a directive which does something like this in its link function angular.module('myApp') .directive('barFoo', function() { return { restrict: 'E', link: function (scope, element) { element.on('click', ....); } }; }); Now I would like to verify in my unit test that it calls on correctly element = angular.element('<bar-foo></bar-foo>'); $compile(element)(scope); spyOn(element, 'on'); ... expect(element.on).toHaveBeenCalled(); It tells me the spy is not called. From what I've found on the