jasmine

How to mock Blob and Click() in jasmine Specs in angular js

℡╲_俬逩灬. 提交于 2019-12-05 12:44:21
How to write Jasmine specs for Blob and Click() event. Every time I am running Specs its downloading file. Can I mock this (and browser also). Thanks var csvFile = "a,b,c",filename="abc.csv"; var blob = new Blob([csvFile], { type: 'text/csv;charset=utf-8;' }); if (navigator.msSaveBlob) { // IE 10+ navigator.msSaveBlob(blob, filename); } else { var link = document.createElement("a"); if (link.download !== undefined) { // feature detection // Browsers that support HTML5 download attribute var url = URL.createObjectURL(blob); link.setAttribute("href", url); link.setAttribute("download", filename)

Jasmine js: Add source method for test execution

≯℡__Kan透↙ 提交于 2019-12-05 11:54:16
I have as simple "hello world" project and I want to test the famous hélloWorld function. The project is structured like this: ├── package.json ├── spec │ ├── helloWorldSpec.js │ └── support │ └── jasmine.json └── src └── helloWorld.js And the file content: package.json { "name": "jasmineTest", "version": "0.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "BSD-2-Clause", "dependencies": { "jasmine": "~2.1.0" } } spec/helloWorldSpec.js // var helloWorld = require('../src/helloWorld.js'); describe('Test',

Expected '> ' to equal '> ' in jasmine

时光怂恿深爱的人放手 提交于 2019-12-05 11:01:43
I'm testing jQuery terminal and I got error: Expected '> ' to equal '> '. when testing: $(function() { describe('Terminal plugin', function() { describe('terminal create terminal destroy', function() { var term = $('<div id="term"></div>').appendTo('body').terminal(); it('should have default prompt', function() { var prompt = term.find('.prompt'); expect(prompt.html()).toEqual("<span>> </span>"); expect(prompt.text()).toEqual('> '); }); }); }); }); they are same value I just copy it into console and replace to equal by == or === and it return true .   is not a "regular" space, so "> " and "> "

Angular 2 fakeAsync waiting for timeout in a function using tick()?

别等时光非礼了梦想. 提交于 2019-12-05 10:57:55
问题 I'm trying to get the results from a mock backend in Angular 2 for unit testing. Currently, we are using fakeAsync with a timeout to simulate the passing of time. current working unit test it('timeout (fakeAsync/tick)', fakeAsync(() => { counter.getTimeout(); tick(3000); //manually specify the waiting time })); But, this means that we are limited to a manually defined timeout. Not when the async task is completed. What I'm trying to do is getting tick() to wait until the task is completed

Why call scope.$digest() after $compile(element)(scope) in unit testing

孤街醉人 提交于 2019-12-05 10:29:19
Below is a very common generic scenario used for testing directive: var element,scope; beforeEach(inject(function ($rootScope,$compile) { scope = $rootScope.$new() element = angular.element('<div my-directive></div>') $compile(element)(scope) scope.$digest(); //why? })) I understand $compile(element) returns a function that take a scope parameter and provides it to the element's directive. I also understand that scope.$digest() executes the digest loop and start dirty-checking. With all that said, my question is why you have to call the scope.$digest after calling $compile to make everything

Unit testing the output of $sce.trustAsHtml in Angular

こ雲淡風輕ζ 提交于 2019-12-05 10:25:58
问题 I am writing a REST app in Angular and I want to write unit tests for it (of course!). I have a controller which gets a list of blog posts from a REST service in json and puts the summaries into the $scope, so I can display them in the view. At first the blog posts were just displaying as text ie <p>Blog body</p> , rather than rendering as parsed HTML, until I discovered that you can use ng-bind-html in conjunction with the $sce service. This now works fine in terms of displaying the blog

Disable Jest setTimeout mock

空扰寡人 提交于 2019-12-05 10:11:10
I'm writing a Jest test for code that depends on a websocket library. The websocket library is mocked. I want to send a message, wait for async actions to complete, and check the response. it('sends a message and gets a response', () => { processor(ws).sendMessage() // do a bunch of async stuff, call websocket.sendMessage() setTimeout(() => { expect(ws.getResponse()).toEqual('all done') }, 100) }) Unfortunately because Jest mocks setTimeout, setTimeout fails. If I run jest.runAllTimers() , the timeout happens instantaneously, so fails to pick up the message. Any idea how to convince jest to

Jasmine date mocking with moment.js

天大地大妈咪最大 提交于 2019-12-05 09:52:53
问题 I'm using moment.js for date/time in my application, but it seems like it doesn't play well with Jasmine's mocking capabilities. I've put together a test suite below that shows my issue: jasmine.clock().mockDate doesn't seem to work for moment, while it works fine for Date . describe('Jasmine tests', function () { beforeEach(function() { jasmine.clock().install(); }); afterEach(function() { jasmine.clock().uninstall(); }); // Pass it('uses the mocked time with Date', function() { var today =

Internet Explorer Selenium protractor e2e tests

て烟熏妆下的殇ゞ 提交于 2019-12-05 09:36:52
I would like to add to our CI build process some e2e tests. I have already added them against chrome + firefox (as the simplest ones). But I really want to do it for several IE versions. How is it possible to inject it in build process on linux/mac? I found such article: http://elgalu.github.io/2014/run-protractor-against-internet-explorer-vm/ But looks like it is not 100% what I need. Could some one provide a simple configuration sample? You would need a selenium server , either your own, or at browserstack / SauceLabs . If you are planning to do it on your own, in short, you would need to

How to spy jQuery AJAX request?

元气小坏坏 提交于 2019-12-05 09:23:55
The following two ways of implementing an ajaxRequest (1) (2) should be equivalent. Having said that: Why does the unit test (3) that verifies the callback was executed, succeeds in (1) and fails in (2)? How should I rewrite the test (3) to spy on the success callback in (2)? If I try to stub jQuery.ajax using sinon and the code (2) I get an error. How should I fix it? Please, see the comments in code (3) for more details. (1) ajaxRequest: function (message, callback) { return $.ajax({ url: backendRouter.generate('feedback_send'), type: 'POST', dataType: 'json', data: { message: message },