jasmine

AngularJS - How to test if a function is called from within another function?

痞子三分冷 提交于 2019-11-30 23:07:53
问题 I'm trying to get started with karma-jasmine and I'm wondering why this test fails: it("should call fakeFunction", function() { spyOn(controller, 'addNew'); spyOn(controller, 'fakeFunction'); controller.addNew(); expect(controller.fakeFunction).toHaveBeenCalled(); }); In my controller that I've previously set up for this test I have the following: function addNew() { fakeFunction(3); } function fakeFunction(number) { return number; } both addNew and fakeFunction are exposed using: vm.addNew =

Can I dynamically create a test spec within a callback?

让人想犯罪 __ 提交于 2019-11-30 22:45:31
I want to retrieve a list of elements on a page, and for each one, create a test spec. My (pseudo) code is :- fetchElements().then(element_list) { foreach element { it("should have some property", function() { expect("foo") }) } } When I run this, I get "No specs found", which I guess makes sense since they are being defined off the main path. What's the best way to achieve dynamically created specs? There are major problems preventing it to be easily achieved: the specs you are creating are based on the result of asynchronous code - on the elements Protractor should first find you can only

Why is Karma refusing to serve my JSON fixture (which I'd like to use in my jasmine / angularjs tests)

早过忘川 提交于 2019-11-30 22:22:46
As indicated in this stackoverflow answer , it looks like Karma will serve JSON fixtures. However, I've spent too many hours trying to get it to work in my environment. Reason: I'm doing angular testing and need to load mock HTTP results into the test, as Jasmine doesn't support any global setup/teardown with mock servers and stuff. In my karma config file, I'm defining a fixture as so: files: [ // angular 'angular/angular.min.js', 'angular/angular-route.js', 'angular/mock/angular-mocks.js', // jasmine jquery helper 'jquery-1.10.2.min.js', 'angular/jasmine-jquery.js', // our app '../public/js

Sinon does not seem to spy for an event handler callback

北城余情 提交于 2019-11-30 22:10:04
I'm testing a backbone view with Jasmin, Simon and jasmin-simon. Here is the code: var MessageContainerView = Backbone.View.extend({ id: 'messages', initialize: function() { this.collection.bind('add', this.addMessage, this); }, render: function( event ) { this.collection.each(this.addMessage); return this; }, addMessage: function( message ) { console.log('addMessage called', message); var view = new MessageView({model: message}); $('#' + this.id).append(view.render().el); } }); Actually, all my tests pass but one. I would like to check that addMessage is called whenever I add an item to this

jQuery Trigger Event in AngularJS Karma Test

江枫思渺然 提交于 2019-11-30 21:02:43
I'm trying to test a new directive I'm writing. However, I can't seem to get the keydown event to trigger with jQuery inside Karma/Jasmine. Here is a simplified version of the test : 'use strict'; describe('', function() { var $compile; var $scope; beforeEach(inject(function(_$compile_, _$rootScope_) { $compile = _$compile_; $scope = _$rootScope_.$new(); })); describe('Getting Trigger To Work', function() { it('Should Trigger a KeyDown Event', function() { var el = $compile('<form name="testing"><input id="field1" name="testfield" ng-model="result" type="text" ng-minlength="5" ng-maxlength="50

Check if element has class only with Jasmine test framework

£可爱£侵袭症+ 提交于 2019-11-30 20:54:26
问题 I am using webdriverJS and Jasmine to perform an end-to-end testing of a web page. I would like to test if an element has class under certain circumstances, but I would like to do it using methods from pure jasmine . This is the part of the code where the issue is located: describe('Header bar', function() { it('should show/hide elements accoding to the window position', function() { this.driver.executeScript('scroll(0, 1000)'); var elemSearch = this.driver.findElements(webdriver.By.id(

$httpBackend in AngularJs Jasmine unit test

前提是你 提交于 2019-11-30 20:10:23
I'm unable to get my unit test to work properly. I have a $scope array that starts out empty, but should be filled with an $http.get(). In the real environment, there'd be approx 15 or so objects in the array, but for my unit test I just grabbed 2. For the unit test, I have: expect($scope.stuff.length).toBe(2); But jasmine's error is: Expected 0 to be 2. here's my controller.js: $scope.stuff = []; $scope.getStuff = function () { var url = site.root + 'api/stuff'; $http.get(url) .success(function (data) { $scope.stuff = data; }) .error(function(error) { console.log(error); }); }; and my

Karma jasmine tests: Highlight diff in terminal

大城市里の小女人 提交于 2019-11-30 19:17:51
I'm using Karma with Jasmine for my tests. In some tests, I have large objects that the test relies on. When I do something like expect(obj).toEqual(expectedObj); and obj != expectedObj , I get an error message in my terminal. But this error is really long , because it includes both of the objects, and it's very hard to see, in what parts the two objects are different. So, is there any highlighter for the terminal, that can be used along with karma? This way, it would be much more easy to figure out, what's wrong. I had the same problem and what did it for me was karma-jasmine-diff-reporter .

Debugging jasmine tests with resharper and phantom js

橙三吉。 提交于 2019-11-30 18:50:49
Similar question was already asked some time ago How do you debug Jasmine tests with Resharper? What is suggested there doesn't really work for me (place debugger; in test code). Each time the tests are run, a new browser window opens and thread jumps through debugger. Is there any way to make it work? And also is there any way to debug jasmine tests with phantom runner and Resharper? Thanks in advance To debug in the browser, add the code below to your js test file. jasmine.getEnv().currentRunner_.finishCallback = function () {}; Resharper won't be notified that the test has finished so we

Protractor fails to find Angular

别说谁变了你拦得住时间么 提交于 2019-11-30 18:40:34
I can't seem to get Protractor to realize that Angular is loaded and running. When it opens Chrome my app loads fully in the browser, so I know that Angular is loaded and running correctly. The config file: exports.config = { seleniumServerJar: 'C:/Dev/PrismWeb/selenium/selenium-server-standalone-2.35.0.jar', seleniumPort: null, chromeDriver: 'C:/Dev/PrismWeb/selenium/chromedriver.exe', seleniumArgs: [], seleniumAddress: null, allScriptsTimeout: 110000, specs: ['c:/dev/prismweb/test/e2e/*.js'], capabilities: {'browserName': 'chrome'}, baseUrl: 'http://localhost:8080', rootElement: 'html',