jasmine

When should I use $provide versus Jasmine Spies in my Angular JS Unit tests

安稳与你 提交于 2019-12-03 02:54:08
I work on a large Angular App and initially we done a lot of our tests by using $provide to mock services. However we now have a lot of Jasmine Spies in our tests in order to stub and spy on services. i.e spyOn(myService, 'myMethod').andReturn 'myValue' Should we really be using $provide for this or are there cases where spying on a service is the best approach? In the Angular Tests they use spies for spying on Jquery which I would see as an external service. spyOn(jq.prototype, 'on'); $provide seems to be used more for internal services. module(function($provide){ $provide.provider('

Print message on expect() assert failure

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to print a custom error message when a Jasmine expect() fails? As an example, for end to end testing I have an array of web pages and I use one test to go to each URL and assert an element exists on each page. I know I can put every expect() into a separate test, but I'd rather iterate through the array and log the page URL on failure. 回答1: UPDATE I see people still are finding this. Later information from the Jasmine team is that there is an undocumented feature on the expect - you can include a custom failure message and it

Error: Cannot find module 'jasmine-core'

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I installed the following for testing: "devDependencies": { "jasmine-core": "^2.4.1", "karma": "^0.13.22", "karma-jasmine": "^0.3.7", "karma-phantomjs-launcher": "^1.0.0" } After running karma start I get the following error: Doing a search this is the first question with the same problem: karma start Cannot find module 'jasmine-core' However I've tried both answers, installed jasmine-core globally and I already did npm install jasmine-core --save-dev :( My test/index.html <!DOCTYPE html> <html lang="en"> <head> <title>Jasmine Spec Runner<

Testing for focus an AngularJS directive

独自空忆成欢 提交于 2019-12-03 02:28:40
How can you test for focus in an AngularJS directive? I would expect the following to work: describe('focus test', function(){ it('should focus element', function(){ var element = $('<input type="text" />'); // Append to body because otherwise it can't be foccused element.appendTo(document.body); element.focus(); expect(element.is(':focus')).toBe(true); }); }); However, this only works in IE, it fails in Firefox and Chrome Update: The solution by @S McCrohan works. Using this I created a 'toHaveFocus' matcher: beforeEach(function(){ this.addMatchers({ toHaveFocus: function(){ this.message =

What line is causing this Protractor error?

匿名 (未验证) 提交于 2019-12-03 02:26:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way for Protractor to show in the console log what line the error occurred on? I just get this type of message: Message: Failed: Cannot call method 'click' of undefined Stack: Error: Failed: Cannot call method 'click' of undefined at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:104:16 at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15 at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/usr/local/lib/node_modules/protractor/node_modules

Javascript.confirm() and Angularjs Karma e2e test

两盒软妹~` 提交于 2019-12-03 02:25:27
I have an Angularjs application that uses simple javascript confirm before executing some actions. Controller: function TokenController($scope) { $scope.token = 'sampleToken'; $scope.newToken = function() { if (confirm("Are you sure you want to change the token?") == true) { $scope.token = 'modifiedToken'; } }; } View: <div id="tokenDiv"> Token:{{token}} <button ng-click="newToken()">New Token</button> </div> Now I want to have an end to end test to check the token is being replaced correctly in the view. How can I intercept the javascript.confirm() call so it doesn't stop the execution of the

Custom Jasmine reporter in Protractor tests

匿名 (未验证) 提交于 2019-12-03 02:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I can not find how to change reporter style in protractors runner using jasmine framework. What I have right now is: But I would like something more like: Is there a way to add custom reporter for jasmine that would show current test running instead of DOTS and Fs? 回答1: I am building a jasmine reporter that does exactly what you want, jasmine-spec-reporter . 回答2: Add the isVerbose flag to the protractor config, it's false by default: exports.config = { . . . // Options to be passed to Jasmine-node. jasmineNodeOpts: { showColors: true,

Check if element has class only with Jasmine test framework

匿名 (未验证) 提交于 2019-12-03 02:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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('animatedElement, animatedElement2, animatedElement3'));

How to debug PhantomJS when running through Karma

最后都变了- 提交于 2019-12-03 02:20:17
I test through Jasmine, Karma and a variety of browsers. I'm currently debugging a test that fails only in PhantomJS. I'd like to debug this call, so I've setup a custom PhantomJS launcher in karma that runs it with the debug port open. I'm able to access the remote debugger in Chrome through that port, however, it seems to know nothing about any of my test files. It reports an "about:blank" and a "localhost:9876" (the karma server that Phantom is hitting) but when I try to debug that location, it shows none of the source files or Jasmine spec files. Has anyone else seen this behavior? I've

mock object for document element

那年仲夏 提交于 2019-12-03 02:19:51
问题 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? 回答1: I think you should mock getElementById to return a dummy HTMLElement JASMINE V1.3 OR BELOW