jasmine

Running specs by tag

时间秒杀一切 提交于 2019-12-18 07:04:07
问题 In Python and nosetests testing framework there is this idea of tagging your tests: from nose.plugins.attrib import attr @attr(speed='slow') def test_big_download(): ... and running the tests that have only specific tags: nosetests -a speed=slow This is very helpful when there is a need to run tests from a specific category or type. Is there anything similar in protractor + jasmine ? The closest functionality I've found is the 'grep' option introduced in 1.6.0 : protractor conf.js --grep=

Accessing compiled template in unit tests

让人想犯罪 __ 提交于 2019-12-18 06:54:01
问题 Most of the Angular tutorials talk about using end to end tests with Protractor to test whether the compiled template came out as expected. I'm wondering if it's possible to do this with unit tests at all. Most of the tutorials that do talk about referencing HTML code in unit tests describe compiling your own written code in the test, for example, to make sure a directive is being accessed correctly: describe('some function', function () { it('should do something', inject(function ($compile,

Accessing compiled template in unit tests

做~自己de王妃 提交于 2019-12-18 06:53:09
问题 Most of the Angular tutorials talk about using end to end tests with Protractor to test whether the compiled template came out as expected. I'm wondering if it's possible to do this with unit tests at all. Most of the tutorials that do talk about referencing HTML code in unit tests describe compiling your own written code in the test, for example, to make sure a directive is being accessed correctly: describe('some function', function () { it('should do something', inject(function ($compile,

Is jasmine supposed to execute specs in the order they are declared or in a random order?

亡梦爱人 提交于 2019-12-18 05:28:26
问题 un-comment the last spec. All hell breaks loose... why? describe('test', function() { var index = 1; it('test 1', function() { expect(index).toBe(1); index++; }); it('test 2', function() { expect(index).toBe(2); index++; }); it('test 3', function() { expect(index).toBe(3); index++; }); it('test 4', function() { expect(index).toBe(4); index++; }); it('test 5', function() { expect(index).toBe(5); index++; }); it('test 6', function() { expect(index).toBe(6); index++; }); it('test 7', function()

How to load external Json file using karma+Jasmine for angularJS testing?/

故事扮演 提交于 2019-12-18 04:52:47
问题 Can anyone provide me an example in PLUNKER that how to load JSON file for karma/jasmine test.I want to read the data from JSON file for the test cases i am writing.I have been searching but nowhere they mentioned clear example on how to do it? I appreciate it if anyone can provide with the example. 回答1: You can load an external json data file using require var data = require('./data.json'); console.log(data); // Your test cases goes here and you can use data object 回答2: Set the path to find

Testing $scope in AngularJs controller with dependency on $filter

半城伤御伤魂 提交于 2019-12-18 04:32:37
问题 I've gone through a few tutorials and basic examples but I'm having a hard time writing unit tests for my controller. I've seen code snippets instantiating controllers and letting angular inject the $rootScope object which in turn is used to create a new scope object for the controller. But I can't figure out why ctrl.$scope ? is undefined : describe('EmployeeCtrl', function () { var scope, ctrl, $httpBackend; beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, $filter) {

How to stop protractor from running further testcases on failure?

只愿长相守 提交于 2019-12-18 01:58:29
问题 Is there a way of quitting test suite and stop executing further test cases, if a test case fails in protractor? 回答1: In case of jasmine testing framework, you are not the first asking about it. There are relevant open discussions/issues on exiting after a first failure, --fail-fast option: Bail on first failure --fail-fast option? Please add --fail-fast support Long story short, this is an open issue and some day jasmine would have the functionality built-in. Currently, use a third-party

How to stop protractor from running further testcases on failure?

我只是一个虾纸丫 提交于 2019-12-18 01:57:23
问题 Is there a way of quitting test suite and stop executing further test cases, if a test case fails in protractor? 回答1: In case of jasmine testing framework, you are not the first asking about it. There are relevant open discussions/issues on exiting after a first failure, --fail-fast option: Bail on first failure --fail-fast option? Please add --fail-fast support Long story short, this is an open issue and some day jasmine would have the functionality built-in. Currently, use a third-party

前端测试框架对比(js单元测试框架对比)

落爺英雄遲暮 提交于 2019-12-17 23:49:41
前端测试框架对比(js单元测试框架对比) 本文主要目的在于横评业界主流的几款前端框架,顺带说下相关的一些内容。 测试分类 通常应用会有 单元测试(Unit tests) 和 功能测试(Functional tests),复杂大型应用可能会有整合测试(Integration tests)。 其中: 单元测试:关注应用中每个零部件的正常运转,防止后续修改影响之前的组件。 功能测试:确保其整体表现符合预期,关注能否让用户正常使用。 整合测试:确保单独运行正常的零部件整合到一起之后依然能正常运行。 详细资料1 详细资料2 开发人员主要关注单元测试,作为开发中的反馈。本文重点讨论的单元测试框架。 单元测试的好处: 如果能通过单元测试,那么通过后续测试且软件整体正常运行的概率大大提高。 单元测试发现的问题定位到细节,容易修改,节省时间。 追踪问题变得更加方便。 选择单元测试框架 单元测试应该:简单,快速执行,清晰的错误报告。 测试框架基本上都做了同一件事儿: 描述你要测试的东西 对其进行测试 判断是否符合预期 选择框架会考虑下面的点: 断言(Assertions):用于判断结果是否符合预期。有些框架需要单独的断言库。 适合 TDD / BDD:是否适合 测试驱动型 / 行为驱动型 的测试风格。 异步测试:有些框架对异步测试支持良好。 使用的语言:大部分 js 测试框架使用 js。 用于特定目的

Jasmine 2.0 async done() and angular-mocks inject() in same test it()

空扰寡人 提交于 2019-12-17 23:46:13
问题 My usual test case looks like it("should send get request", inject(function(someServices) { //some test })); And Jasmine 2.0 async test should look like it("should send get request", function(done) { someAsync.then(function(){ done(); }); }); How can I use both done and inject in one test? 回答1: This should work; I ran into the same problem when I updated to Jasmine 2.0 it("should send get request", function(done) { inject(function(someServices) { //some async test done(); })(); // function