jasmine

Don't work $compile in Jasmine Karma Angular

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: ( function () { 'use strict' ; angular . module ( 'app.widgets' ) . directive ( 'analiticsHere' , analitics ); function analitics () { var directive = { template : '<div>hello world</div>' }; return directive ; } })(); Create simple directive. Ant try to test it. inject ( function ( $compile , $rootScope , $templateCache ){ compile = $compile ; scope = $rootScope . $new (); template = $templateCache . get ( 'scripts/widgets/templates/Analytics.html' ); console . log ( template ); //return nothing var element = angular . element ( '

Angular 2 Unit Tests: Cannot find name &#039;describe&#039;

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm following this tutorial from angular.io As they said, I've created hero.spec.ts file to create unit tests: import { Hero } from './hero'; describe('Hero', () => { it('has name', () => { let hero: Hero = {id: 1, name: 'Super Cat'}; expect(hero.name).toEqual('Super Cat'); }); it('has id', () => { let hero: Hero = {id: 1, name: 'Super Cat'}; expect(hero.id).toEqual(1); }); }); Unit Tests work like a charm. The problem is: I see some errors, which are mentioned in tutorial: Our editor and the compiler may complain that they don’t know what

Jasmine, Karma, Angular how to write test on my Angular app?

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have just jumped to another project and, basically, I have been asked to write Unit tests. Since I have already know Protractor for e2e testing, I now switched to Karma and Jasmine to carry out unit testing. I have already downloaded karma, jasmine, karma-jasmine, and karma-chrome-launcher. I installed angular-mocks as well so I should be ready to start. I have read many things on the internet but, now, what I really need is a concrete example of a real app to figure out how to start writing tests. I don't need easy examples but concrete

node_modules/@types/jasmine/index.d.ts: error TS1005: &#039;=&#039; expected

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Earlier I was working with Angular2.3.1 and just updated package.json file using npm update --save to get updated version of Angular2 which is 2.4.7 . But it seems, for some reason, its breaking the code when I do npm start . Its says node_modules/@types/jasmine/index.d.ts(39,52): error TS1005: '=' expected Now, I wonder how to fix it? Any idea? 回答1: After searching in google, came to know that latest version 2.5.43 of @types/jasmine is not compatible with typescript version 2.0.* . So had to upgrade typescript to 2.1.6 . Read more here:

How to create stub for ajax function using Jasmine BDD

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm struggling to find any examples on how to fake an ajax call using Jasmine BDD? I have a custom ajax function that works like so... ajax ({ url : 'JSON.php' , dataType : 'json' , onSuccess : function ( resp ) { console . log ( resp ); } }); ...and I've no idea how to create a stub to fake calling the actual ajax function. I want to avoid calling the ajax function as it could slow down my test suite if a real ajax call to the server takes some time to respond and I've loads of specs in my test suite. I've heard that you can use

QUnit vs Jasmine? [closed]

你离开我真会死。 提交于 2019-12-03 01:17:39
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . 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. 回答1: 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

ReferenceError: Can&#039;t find variable: require at

匿名 (未验证) 提交于 2019-12-03 01:14:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a question about using jasmine with Grunt. I keep getting an error, ReferenceError: Can't find variable: require at whenever I run my jasmine tests. Here is my jasmine entry for my Gruntfile.js : jasmine: { js: { src: jsFiles, options: { specs: 'tests/*_spec.js', helpers: 'tests/helpers/*', vendor: 'vendor/*' } } }, I can run a dummy test without a require just fine, but when I include a require in a test, like so, I get the require error. var testD = require('../src/events_to_actions'); describe("events_to_actions", function() { it(

jasmine: spyOn(obj, &#039;method&#039;).andCallFake or and.callFake?

匿名 (未验证) 提交于 2019-12-03 01:13:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to mock test data in my Jasmine tests. Here are two versions: // version 1: spyOn(mBankAccountResource, 'getBankAccountData').and.callFake(fakedFunction); // version 2: spyOn(mBankAccountResource, 'getBankAccountData').andCallFake(fakedFunction); When I execute my tests with a browser (Chrome, Firefox) then the first version works. However, when I run the same test with phantomjs, I have to use the second version. Otherwise, it complains that the function is not defined. Here are the error messages: // phantomjs (with version 1)

How to spyOn a value property (rather than a method) with Jasmine

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Jasmine's spyOn is good to change a method's behavior, but is there any way to change a value property (rather than a method) for an object? the code could be like below: spyOn(myObj, 'valueA').andReturn(1); expect(myObj.valueA).toBe(1); 回答1: In February 2017, they merged a PR adding this feature, they released in April 2017. so to spy on getters/setters you use: const spy = spyOnProperty(myObj, 'myGetterName', 'get'); where myObj is your instance, 'myGetterName' is the name of that one defined in your class as get myGetterName() {} and the

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

谁说我不能喝 提交于 2019-12-03 01:00:20
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . 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. 回答1: I have done testing in both Jasmine and Mocha. First, switching is relatively easy. The