How to use suiteDone method in root

Best JavaScript code snippet using root

EnvSpec.js

Source:EnvSpec.js Github

copy

Full Screen

1describe('Env integration', function() {2 var env;3 beforeEach(function() {4 jasmine.getEnv().registerIntegrationMatchers();5 env = new jasmineUnderTest.Env();6 });7 afterEach(function() {8 env.cleanup_();9 });10 it('Suites execute as expected (no nesting)', function(done) {11 var calls = [];12 var assertions = function() {13 expect(calls).toEqual(['with a spec', 'and another spec']);14 done();15 };16 env.configure({ random: false });17 env.describe('A Suite', function() {18 env.it('with a spec', function() {19 calls.push('with a spec');20 });21 env.it('and another spec', function() {22 calls.push('and another spec');23 });24 });25 env.execute(null, assertions);26 });27 it('Nested Suites execute as expected', function(done) {28 var calls = [];29 var assertions = function() {30 expect(calls).toEqual([31 'an outer spec',32 'an inner spec',33 'another inner spec'34 ]);35 done();36 };37 env.configure({ random: false });38 env.describe('Outer suite', function() {39 env.it('an outer spec', function() {40 calls.push('an outer spec');41 });42 env.describe('Inner suite', function() {43 env.it('an inner spec', function() {44 calls.push('an inner spec');45 });46 env.it('another inner spec', function() {47 calls.push('another inner spec');48 });49 });50 });51 env.execute(null, assertions);52 });53 it('Multiple top-level Suites execute as expected', function(done) {54 var calls = [];55 var assertions = function() {56 expect(calls).toEqual([57 'an outer spec',58 'an inner spec',59 'another inner spec',60 'a 2nd outer spec'61 ]);62 done();63 };64 env.configure({ random: false });65 env.describe('Outer suite', function() {66 env.it('an outer spec', function() {67 calls.push('an outer spec');68 });69 env.describe('Inner suite', function() {70 env.it('an inner spec', function() {71 calls.push('an inner spec');72 });73 env.it('another inner spec', function() {74 calls.push('another inner spec');75 });76 });77 });78 env.describe('Another outer suite', function() {79 env.it('a 2nd outer spec', function() {80 calls.push('a 2nd outer spec');81 });82 });83 env.execute(null, assertions);84 });85 it('explicitly fails a spec', function(done) {86 var specDone = jasmine.createSpy('specDone');87 env.addReporter({ specDone: specDone });88 env.describe('failing', function() {89 env.it('has a default message', function() {90 env.fail();91 });92 env.it('specifies a message', function() {93 env.fail('messy message');94 });95 env.it('has a message and stack trace from an Error', function() {96 env.fail(new Error('error message'));97 });98 env.it('pretty prints objects', function() {99 env.fail({ prop: 'value', arr: ['works', true] });100 });101 });102 env.execute(null, function() {103 expect(specDone).toHaveBeenCalledWith(104 jasmine.objectContaining({105 description: 'has a default message',106 failedExpectations: [107 jasmine.objectContaining({108 message: 'Failed'109 })110 ]111 })112 );113 expect(specDone).toHaveBeenCalledWith(114 jasmine.objectContaining({115 description: 'specifies a message',116 failedExpectations: [117 jasmine.objectContaining({118 message: 'Failed: messy message'119 })120 ]121 })122 );123 expect(specDone).toHaveBeenCalledWith(124 jasmine.objectContaining({125 description: 'has a message and stack trace from an Error',126 failedExpectations: [127 jasmine.objectContaining({128 message: 'Failed: error message',129 stack: {130 asymmetricMatch: function(other) {131 if (!other) {132 // IE doesn't give us a stacktrace so just ignore it.133 return true;134 }135 var split = other.split('\n'),136 firstLine = split[0];137 if (firstLine.indexOf('error message') >= 0) {138 // Chrome inserts the message and a newline before the first stacktrace line.139 firstLine = split[1];140 }141 return firstLine.indexOf('EnvSpec') >= 0;142 }143 }144 })145 ]146 })147 );148 expect(specDone).toHaveBeenCalledWith(149 jasmine.objectContaining({150 description: 'pretty prints objects',151 failedExpectations: [152 jasmine.objectContaining({153 message:154 "Failed: Object({ prop: 'value', arr: [ 'works', true ] })"155 })156 ]157 })158 );159 done();160 });161 });162 it("produces an understandable error message when 'fail' is used outside of a current spec", function(done) {163 env.describe('A Suite', function() {164 env.it('an async spec that is actually synchronous', function(165 underTestCallback166 ) {167 underTestCallback();168 });169 expect(function() {170 env.fail();171 }).toThrowError(/'fail' was used when there was no current spec/);172 });173 env.execute(null, done);174 });175 it("calls associated befores/specs/afters with the same 'this'", function(done) {176 env.configure({ random: false });177 env.describe('tests', function() {178 var firstTimeThrough = true,179 firstSpecContext,180 secondSpecContext;181 env.beforeEach(function() {182 if (firstTimeThrough) {183 firstSpecContext = this;184 } else {185 secondSpecContext = this;186 }187 expect(this).toEqual(new jasmineUnderTest.UserContext());188 });189 env.it('sync spec', function() {190 expect(this).toBe(firstSpecContext);191 });192 env.it('another sync spec', function() {193 expect(this).toBe(secondSpecContext);194 });195 env.afterEach(function() {196 if (firstTimeThrough) {197 expect(this).toBe(firstSpecContext);198 firstTimeThrough = false;199 } else {200 expect(this).toBe(secondSpecContext);201 }202 });203 });204 env.execute(null, done);205 });206 it("calls associated befores/its/afters with the same 'this' for an async spec", function(done) {207 env.describe('with an async spec', function() {208 var specContext;209 env.beforeEach(function() {210 specContext = this;211 expect(this).toEqual(new jasmineUnderTest.UserContext());212 });213 env.it('sync spec', function(underTestCallback) {214 expect(this).toBe(specContext);215 underTestCallback();216 });217 env.afterEach(function() {218 expect(this).toBe(specContext);219 });220 });221 env.execute(null, done);222 });223 it('calls associated beforeAlls/afterAlls only once per suite', function(done) {224 var before = jasmine.createSpy('beforeAll'),225 after = jasmine.createSpy('afterAll');226 env.describe('with beforeAll and afterAll', function() {227 env.it('spec', function() {228 expect(before).toHaveBeenCalled();229 expect(after).not.toHaveBeenCalled();230 });231 env.it('another spec', function() {232 expect(before).toHaveBeenCalled();233 expect(after).not.toHaveBeenCalled();234 });235 env.beforeAll(before);236 env.afterAll(after);237 });238 env.execute(null, function() {239 expect(after).toHaveBeenCalled();240 expect(after.calls.count()).toBe(1);241 expect(before.calls.count()).toBe(1);242 done();243 });244 });245 it('calls associated beforeAlls/afterAlls only once per suite for async', function(done) {246 var before = jasmine.createSpy('beforeAll'),247 after = jasmine.createSpy('afterAll');248 env.describe('with beforeAll and afterAll', function() {249 env.it('spec', function() {250 expect(before).toHaveBeenCalled();251 expect(after).not.toHaveBeenCalled();252 });253 env.it('another spec', function() {254 expect(before).toHaveBeenCalled();255 expect(after).not.toHaveBeenCalled();256 });257 env.beforeAll(function(beforeCallbackUnderTest) {258 before();259 beforeCallbackUnderTest();260 });261 env.afterAll(function(afterCallbackUnderTest) {262 after();263 afterCallbackUnderTest();264 });265 });266 env.execute(null, function() {267 expect(after).toHaveBeenCalled();268 expect(after.calls.count()).toBe(1);269 expect(before.calls.count()).toBe(1);270 done();271 });272 });273 it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) {274 env.describe('with beforeAll and afterAll', function() {275 env.beforeAll(function() {276 this.x = 1;277 });278 env.it('has an x at the root', function() {279 expect(this.x).toBe(1);280 });281 env.describe('child that deletes', function() {282 env.beforeAll(function() {283 expect(this.x).toBe(1);284 delete this.x;285 });286 env.it('has no x', function() {287 expect(this.x).not.toBeDefined();288 });289 });290 env.describe('child should still have x', function() {291 env.beforeAll(function(innerDone) {292 expect(this.x).toBe(1);293 innerDone();294 });295 env.it('has an x', function() {296 expect(this.x).toBe(1);297 delete this.x;298 });299 env.it('still has an x', function() {300 expect(this.x).toBe(1);301 });302 env.it('adds a y', function() {303 this.y = 2;304 expect(this.y).toBe(2);305 });306 env.it("doesn't have y that was added in sibling", function() {307 expect(this.y).not.toBeDefined();308 });309 });310 });311 env.execute(null, done);312 });313 it('tags top-level afterAll failures with a type', function(done) {314 var jasmineDone = jasmine.createSpy('jasmineDone');315 env.it('has a spec', function() {});316 env.afterAll(function() {317 throw 'nope';318 });319 env.addReporter({ jasmineDone: jasmineDone });320 env.execute(null, function() {321 {322 var result = jasmineDone.calls.argsFor(0)[0];323 expect(result.failedExpectations[0].globalErrorType).toEqual(324 'afterAll'325 );326 done();327 }328 });329 });330 it('does not tag suite afterAll failures with a type', function(done) {331 var reporter = {332 suiteDone: jasmine.createSpy('suiteDone').and.callFake(function(result) {333 expect(result.failedExpectations[0].globalErrorType).toBeFalsy();334 })335 };336 env.addReporter(reporter);337 env.describe('a suite', function() {338 env.it('has a spec', function() {});339 env.afterAll(function() {340 throw 'nope';341 });342 });343 env.execute(null, function() {344 expect(reporter.suiteDone).toHaveBeenCalled();345 done();346 });347 });348 it('when the beforeAll fails, error at suite level', function(done) {349 var reporter = jasmine.createSpyObj('fakeReporter', [350 'specDone',351 'suiteDone'352 ]);353 var assertions = function() {354 expect(reporter.specDone.calls.count()).toEqual(2);355 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(356 'A suite spec that will pass',357 []358 );359 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(360 'A suite nesting another spec to pass',361 []362 );363 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(364 'A suite',365 ['Expected 1 to be 2.']366 );367 done();368 };369 env.addReporter(reporter);370 env.describe('A suite', function() {371 env.beforeAll(function() {372 env.expect(1).toBe(2);373 });374 env.it('spec that will pass', function() {});375 env.describe('nesting', function() {376 env.it('another spec to pass', function() {});377 });378 });379 env.execute(null, assertions);380 });381 it('copes with async failures after done has been called', function(done) {382 if (jasmine.getEnv().skipBrowserFlake) {383 jasmine.getEnv().skipBrowserFlake();384 }385 var global = {386 setTimeout: function(fn, delay) {387 setTimeout(fn, delay);388 },389 clearTimeout: function(fn, delay) {390 clearTimeout(fn, delay);391 }392 };393 spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);394 env.cleanup_();395 env = new jasmineUnderTest.Env();396 var reporter = jasmine.createSpyObj('fakeReporter', [397 'specDone',398 'suiteDone'399 ]);400 var assertions = function() {401 expect(reporter.specDone).not.toHaveFailedExpectationsForRunnable(402 'A suite fails',403 ['fail thrown']404 );405 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(406 'A suite',407 ['fail thrown']408 );409 done();410 };411 env.addReporter(reporter);412 env.fdescribe('A suite', function() {413 env.it('fails', function(specDone) {414 setTimeout(function() {415 specDone();416 setTimeout(function() {417 setTimeout(function() {418 global.onerror('fail');419 });420 });421 });422 });423 });424 env.describe('Ignored', function() {425 env.it('is not run', function() {});426 });427 env.execute(null, assertions);428 });429 describe('suiteDone reporting', function() {430 it('reports when an afterAll fails an expectation', function(done) {431 var reporter = jasmine.createSpyObj('fakeReport', ['suiteDone']);432 var assertions = function() {433 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(434 'my suite',435 ['Expected 1 to equal 2.', 'Expected 2 to equal 3.']436 );437 done();438 };439 env.addReporter(reporter);440 env.describe('my suite', function() {441 env.it('my spec', function() {});442 env.afterAll(function() {443 env.expect(1).toEqual(2);444 env.expect(2).toEqual(3);445 });446 });447 env.execute(null, assertions);448 });449 it('if there are no specs, it still reports correctly', function(done) {450 var reporter = jasmine.createSpyObj('fakeReport', ['suiteDone']);451 var assertions = function() {452 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(453 'outer suite',454 ['Expected 1 to equal 2.', 'Expected 2 to equal 3.']455 );456 done();457 };458 env.addReporter(reporter);459 env.describe('outer suite', function() {460 env.describe('inner suite', function() {461 env.it('spec', function() {});462 });463 env.afterAll(function() {464 env.expect(1).toEqual(2);465 env.expect(2).toEqual(3);466 });467 });468 env.execute(null, assertions);469 });470 it('reports when afterAll throws an exception', function(done) {471 var error = new Error('After All Exception'),472 reporter = jasmine.createSpyObj('fakeReport', ['suiteDone']);473 var assertions = function() {474 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(475 'my suite',476 [/^Error: After All Exception/]477 );478 done();479 };480 env.addReporter(reporter);481 env.describe('my suite', function() {482 env.it('my spec', function() {});483 env.afterAll(function() {484 throw error;485 });486 });487 env.execute(null, assertions);488 });489 it('reports when an async afterAll fails an expectation', function(done) {490 var reporter = jasmine.createSpyObj('fakeReport', ['suiteDone']);491 var assertions = function() {492 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(493 'my suite',494 ['Expected 1 to equal 2.']495 );496 done();497 };498 env.addReporter(reporter);499 env.describe('my suite', function() {500 env.it('my spec', function() {});501 env.afterAll(function(afterAllDone) {502 env.expect(1).toEqual(2);503 afterAllDone();504 });505 });506 env.execute(null, assertions);507 });508 it('reports when an async afterAll throws an exception', function(done) {509 var error = new Error('After All Exception'),510 reporter = jasmine.createSpyObj('fakeReport', ['suiteDone']);511 var assertions = function() {512 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(513 'my suite',514 [/^Error: After All Exception/]515 );516 done();517 };518 env.addReporter(reporter);519 env.describe('my suite', function() {520 env.it('my spec', function() {});521 env.afterAll(function(afterAllDone) {522 throw error;523 });524 });525 env.execute(null, assertions);526 });527 it('reports the duration of the suite', function(done) {528 var duration;529 env.addReporter({530 suiteDone: function(result) {531 expect(duration).toBeUndefined();532 duration = result.duration;533 }534 });535 env.describe('my suite', function() {536 env.it('takes time', function(done) {537 // We can't just use the mock clock here because the timer is designed538 // to record real time even when the mock clock is installed.539 setTimeout(done, 10);540 });541 });542 env.execute(null, function() {543 // Expect > 0 to compensate for clock imprecision544 expect(duration).toBeGreaterThan(0);545 done();546 });547 });548 });549 describe('specDone reporting', function() {550 it('reports the duration of the spec', function(done) {551 var duration;552 env.addReporter({553 specDone: function(result) {554 expect(duration).toBeUndefined();555 duration = result.duration;556 }557 });558 env.describe('my suite', function() {559 env.it('takes time', function(done) {560 // We can't just use the mock clock here because the timer is designed561 // to record real time even when the mock clock is installed.562 setTimeout(done, 10);563 });564 });565 env.execute(null, function() {566 // Expect > 0 to compensate for clock imprecision567 expect(duration).toBeGreaterThan(0);568 done();569 });570 });571 });572 it('reports expectation failures in global beforeAll', function(done) {573 var reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']);574 env.beforeAll(function() {575 env.expect(1).toBe(0);576 });577 env.it('is a spec', function() {578 env.expect(true).toBe(true);579 });580 env.addReporter(reporter);581 env.execute(null, function() {582 var results = reporter.jasmineDone.calls.argsFor(0)[0];583 expect(results.failedExpectations).toEqual([584 jasmine.objectContaining({ message: 'Expected 1 to be 0.' })585 ]);586 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(587 'is a spec',588 []589 );590 done();591 });592 });593 it('reports expectation failures in global afterAll', function(done) {594 var reporter = jasmine.createSpyObj(['jasmineDone']);595 env.afterAll(function() {596 env.expect(1).toBe(0);597 });598 env.it('is a spec', function() {599 env.expect(true).toBe(true);600 });601 env.addReporter(reporter);602 env.execute(null, function() {603 var results = reporter.jasmineDone.calls.argsFor(0)[0];604 expect(results.failedExpectations).toEqual([605 jasmine.objectContaining({ message: 'Expected 1 to be 0.' })606 ]);607 done();608 });609 });610 it('Allows specifying which specs and suites to run', function(done) {611 var calls = [],612 suiteCallback = jasmine.createSpy('suite callback'),613 firstSpec,614 secondSuite;615 env.addReporter({ suiteDone: suiteCallback });616 env.describe('first suite', function() {617 firstSpec = env.it('first spec', function() {618 calls.push('first spec');619 });620 env.it('second spec', function() {621 calls.push('second spec');622 });623 });624 secondSuite = env.describe('second suite', function() {625 env.it('third spec', function() {626 calls.push('third spec');627 });628 });629 env.execute([secondSuite.id, firstSpec.id], function() {630 expect(calls).toEqual(['third spec', 'first spec']);631 expect(suiteCallback).toHaveBeenCalled();632 done();633 });634 });635 it('runs before and after all functions for runnables provided to .execute()', function(done) {636 var calls = [],637 first_spec,638 second_spec;639 env.describe('first suite', function() {640 env.beforeAll(function() {641 calls.push('before');642 });643 env.afterAll(function() {644 calls.push('after');645 });646 first_spec = env.it('spec', function() {647 calls.push('first spec');648 });649 second_spec = env.it('spec 2', function() {650 calls.push('second spec');651 });652 });653 env.execute([first_spec.id, second_spec.id], function() {654 expect(calls).toEqual(['before', 'first spec', 'second spec', 'after']);655 done();656 });657 });658 it('Allows filtering out specs and suites to run programmatically', function(done) {659 var calls = [],660 suiteCallback = jasmine.createSpy('suite callback'),661 firstSpec,662 secondSuite;663 env.addReporter({ suiteDone: suiteCallback });664 env.describe('first suite', function() {665 env.it('first spec', function() {666 calls.push('first spec');667 });668 env.it('second spec', function() {669 calls.push('second spec');670 });671 });672 secondSuite = env.describe('second suite', function() {673 env.it('third spec', function() {674 calls.push('third spec');675 });676 });677 env.configure({678 specFilter: function(spec) {679 return /^first suite/.test(spec.getFullName());680 }681 });682 env.execute(null, function() {683 expect(calls.length).toEqual(2);684 expect(calls).toEqual(685 jasmine.arrayContaining(['first spec', 'second spec'])686 );687 expect(suiteCallback).toHaveBeenCalled();688 done();689 });690 });691 it('Functions can be spied on and have their calls tracked', function(done) {692 var originalFunctionWasCalled = false;693 var subject = {694 spiedFunc: function() {695 originalFunctionWasCalled = true;696 return 'original result';697 }698 };699 env.it('works with spies', function() {700 var spy = env701 .spyOn(subject, 'spiedFunc')702 .and.returnValue('stubbed result');703 expect(subject.spiedFunc).toEqual(spy);704 expect(subject.spiedFunc.calls.any()).toEqual(false);705 expect(subject.spiedFunc.calls.count()).toEqual(0);706 subject.spiedFunc('foo');707 expect(subject.spiedFunc.calls.any()).toEqual(true);708 expect(subject.spiedFunc.calls.count()).toEqual(1);709 expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['foo']);710 expect(subject.spiedFunc.calls.mostRecent().object).toEqual(subject);711 expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual(712 'stubbed result'713 );714 expect(originalFunctionWasCalled).toEqual(false);715 subject.spiedFunc.and.callThrough();716 subject.spiedFunc('bar');717 expect(subject.spiedFunc.calls.count()).toEqual(2);718 expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['bar']);719 expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual(720 'original result'721 );722 expect(originalFunctionWasCalled).toEqual(true);723 });724 env.it(725 'works with constructors when using callThrough spy strategy',726 function() {727 function MyClass(foo) {728 if (!(this instanceof MyClass))729 throw new Error('You must use the new keyword.');730 this.foo = foo;731 }732 var subject = { MyClass: MyClass };733 var spy = env.spyOn(subject, 'MyClass').and.callThrough();734 expect(function() {735 var result = new spy('hello world');736 expect(result instanceof MyClass).toBeTruthy();737 expect(result.foo).toEqual('hello world');738 }).not.toThrow();739 expect(function() {740 var result = new spy(741 'passing',742 'extra',743 'arguments',744 'to',745 'constructor'746 );747 expect(result instanceof MyClass).toBeTruthy();748 expect(result.foo).toEqual('passing');749 }).not.toThrow();750 expect(function() {751 spy('hello world');752 }).toThrowError('You must use the new keyword.');753 }754 );755 env.execute(null, done);756 });757 it('can be configured to allow respying on functions', function(done) {758 var foo = {759 bar: function() {760 return 1;761 }762 };763 env.allowRespy(true);764 env.describe('test suite', function() {765 env.it('spec 0', function() {766 env.spyOn(foo, 'bar');767 var error = null;768 expect(function() {769 env.spyOn(foo, 'bar');770 }).not.toThrow();771 });772 });773 env.execute(null, done);774 });775 it('removes all spies added in a spec after the spec is complete', function(done) {776 var originalFoo = function() {},777 testObj = {778 foo: originalFoo779 },780 firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {781 env.spyOn(testObj, 'foo');782 }),783 secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {784 expect(testObj.foo).toBe(originalFoo);785 });786 env.describe('test suite', function() {787 env.it('spec 0', firstSpec);788 env.it('spec 1', secondSpec);789 });790 env.execute(null, function() {791 expect(firstSpec).toHaveBeenCalled();792 expect(secondSpec).toHaveBeenCalled();793 done();794 });795 });796 it('removes all spies added in a suite after the suite is complete', function(done) {797 var originalFoo = function() {},798 testObj = {799 foo: originalFoo800 };801 env.describe('test suite', function() {802 env.beforeAll(function() {803 env.spyOn(testObj, 'foo');804 });805 env.it('spec 0', function() {806 expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true);807 });808 env.it('spec 1', function() {809 expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true);810 });811 });812 env.describe('another suite', function() {813 env.it('spec 2', function() {814 expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(false);815 });816 });817 env.execute(null, done);818 });819 it('removes a spy from the top suite after the run is complete', function(done) {820 var originalFoo = function() {},821 testObj = {822 foo: originalFoo823 };824 env.beforeAll(function() {825 env.spyOn(testObj, 'foo');826 });827 env.it('spec', function() {828 expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true);829 });830 env.execute(null, function() {831 expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(false);832 done();833 });834 });835 it('Mock clock can be installed and used in tests', function(done) {836 if (jasmine.getEnv().skipBrowserFlake) {837 jasmine.getEnv().skipBrowserFlake();838 }839 var globalSetTimeout = jasmine840 .createSpy('globalSetTimeout')841 .and.callFake(function(cb, t) {842 setTimeout(cb, t);843 }),844 delayedFunctionForGlobalClock = jasmine.createSpy(845 'delayedFunctionForGlobalClock'846 ),847 delayedFunctionForMockClock = jasmine.createSpy(848 'delayedFunctionForMockClock'849 );850 env.cleanup_();851 env = new jasmineUnderTest.Env({852 global: {853 setTimeout: globalSetTimeout,854 clearTimeout: clearTimeout,855 setImmediate: function(cb) {856 setTimeout(cb, 0);857 }858 }859 });860 env.configure({ random: false });861 env.describe('tests', function() {862 env.it('test with mock clock', function() {863 env.clock.install();864 env.clock.setTimeout(delayedFunctionForMockClock, 100);865 env.clock.tick(100);866 env.clock.uninstall();867 });868 env.it('test without mock clock', function() {869 env.clock.setTimeout(delayedFunctionForGlobalClock, 100);870 });871 });872 expect(globalSetTimeout).not.toHaveBeenCalled();873 expect(delayedFunctionForMockClock).not.toHaveBeenCalled();874 env.execute(null, function() {875 expect(delayedFunctionForMockClock).toHaveBeenCalled();876 expect(globalSetTimeout).toHaveBeenCalledWith(877 delayedFunctionForGlobalClock,878 100879 );880 done();881 });882 });883 it('should run async specs in order, waiting for them to complete', function(done) {884 var mutatedVar;885 env.describe('tests', function() {886 env.beforeEach(function() {887 mutatedVar = 2;888 });889 env.it('async spec', function(underTestCallback) {890 setTimeout(function() {891 expect(mutatedVar).toEqual(2);892 underTestCallback();893 }, 0);894 });895 env.it('after async spec', function() {896 mutatedVar = 3;897 });898 });899 env.execute(null, done);900 });901 describe('with a mock clock', function() {902 var realSetTimeout;903 function createMockedEnv() {904 env.cleanup_();905 // explicitly pass in timing functions so we can make sure that clear stack always works906 // no matter how long the suite in the spec is907 env = new jasmineUnderTest.Env({908 global: {909 setTimeout: function(cb, t) {910 var stack = jasmine.util.errorWithStack().stack;911 if (stack.indexOf('ClearStack') >= 0) {912 return realSetTimeout(cb, t);913 } else {914 return setTimeout(cb, t);915 }916 },917 clearTimeout: clearTimeout,918 setInterval: setInterval,919 clearInterval: clearInterval,920 setImmediate: function(cb) {921 realSetTimeout(cb, 0);922 }923 }924 });925 }926 beforeEach(function() {927 this.originalTimeout = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL;928 realSetTimeout = setTimeout;929 jasmine.clock().install();930 });931 afterEach(function() {932 jasmine.clock().tick(1);933 jasmine.clock().tick(1);934 jasmine.clock().uninstall();935 jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = this.originalTimeout;936 });937 it("should wait a default interval before failing specs that haven't called done yet", function(done) {938 createMockedEnv();939 var reporter = jasmine.createSpyObj('fakeReporter', ['specDone']);940 reporter.specDone.and.callFake(function(result) {941 expect(result).toEqual(jasmine.objectContaining({ status: 'failed' }));942 realSetTimeout(function() {943 jasmine.clock().tick(1);944 }, 0);945 });946 env.addReporter(reporter);947 jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 8414;948 env.it("async spec that doesn't call done", function(underTestCallback) {949 env.expect(true).toBeTruthy();950 jasmine.clock().tick(8416);951 jasmine.clock().tick(1);952 });953 env.execute(null, function() {954 expect(reporter.specDone.calls.count()).toEqual(1);955 jasmine.clock().tick(1);956 realSetTimeout(done);957 });958 });959 it('should not use the mock clock for asynchronous timeouts', function(done) {960 if (jasmine.getEnv().skipBrowserFlake) {961 jasmine.getEnv().skipBrowserFlake();962 }963 createMockedEnv();964 var reporter = jasmine.createSpyObj('fakeReporter', ['specDone']),965 clock = env.clock;966 reporter.specDone.and.callFake(function() {967 realSetTimeout(function() {968 jasmine.clock().tick(1);969 }, 0);970 });971 env.addReporter(reporter);972 jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 5;973 env.beforeAll(function() {974 clock.install();975 });976 env.afterAll(function() {977 clock.uninstall();978 });979 env.it('spec that should not time out', function(innerDone) {980 clock.tick(6);981 expect(true).toEqual(true);982 realSetTimeout(innerDone);983 });984 env.execute(null, function() {985 expect(reporter.specDone).toHaveBeenCalledTimes(1);986 expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(987 jasmine.objectContaining({ status: 'passed' })988 );989 jasmine.clock().tick(1);990 realSetTimeout(done);991 });992 });993 it('should wait a custom interval before reporting async functions that fail to complete', function(done) {994 if (jasmine.getEnv().skipBrowserFlake) {995 jasmine.getEnv().skipBrowserFlake();996 }997 createMockedEnv();998 var reporter = jasmine.createSpyObj('fakeReport', [999 'jasmineDone',1000 'suiteDone',1001 'specDone'1002 ]);1003 env.addReporter(reporter);1004 jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 10000;1005 env.describe('suite', function() {1006 env.afterAll(function() {1007 realSetTimeout(function() {1008 try {1009 jasmine.clock().tick(10);1010 } catch (e) {1011 // don't worry if the clock is already uninstalled1012 }1013 }, 100);1014 });1015 env.describe('beforeAll', function() {1016 env.beforeAll(function(innerDone) {1017 realSetTimeout(function() {1018 jasmine.clock().tick(5001);1019 }, 0);1020 }, 5000);1021 env.it('times out', function(innerDone) {1022 realSetTimeout(function() {1023 jasmine.clock().tick(1);1024 innerDone();1025 }, 0);1026 });1027 });1028 env.describe('afterAll', function() {1029 env.afterAll(function(innerDone) {1030 realSetTimeout(function() {1031 jasmine.clock().tick(2001);1032 }, 0);1033 }, 2000);1034 env.it('times out', function(innerDone) {1035 realSetTimeout(function() {1036 jasmine.clock().tick(1);1037 innerDone();1038 }, 0);1039 });1040 });1041 env.describe('beforeEach', function() {1042 env.beforeEach(function(innerDone) {1043 realSetTimeout(function() {1044 jasmine.clock().tick(1001);1045 }, 0);1046 }, 1000);1047 env.it('times out', function(innerDone) {1048 realSetTimeout(function() {1049 jasmine.clock().tick(1);1050 innerDone();1051 }, 0);1052 });1053 });1054 env.describe('afterEach', function() {1055 env.afterEach(function(innerDone) {1056 realSetTimeout(function() {1057 jasmine.clock().tick(4001);1058 }, 0);1059 }, 4000);1060 env.it('times out', function(innerDone) {1061 realSetTimeout(function() {1062 jasmine.clock().tick(1);1063 innerDone();1064 }, 0);1065 });1066 });1067 env.it(1068 'it times out',1069 function(innerDone) {1070 realSetTimeout(function() {1071 jasmine.clock().tick(6001);1072 }, 0);1073 },1074 60001075 );1076 });1077 env.execute(null, function() {1078 var r = reporter.jasmineDone.calls.argsFor(0)[0];1079 expect(r.failedExpectations).toEqual([]);1080 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(1081 'suite beforeAll',1082 [1083 /^Error: Timeout - Async function did not complete within 5000ms \(custom timeout\)/1084 ]1085 );1086 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(1087 'suite afterAll',1088 [1089 /^Error: Timeout - Async function did not complete within 2000ms \(custom timeout\)/1090 ]1091 );1092 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1093 'suite beforeEach times out',1094 [1095 /^Error: Timeout - Async function did not complete within 1000ms \(custom timeout\)/1096 ]1097 );1098 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1099 'suite afterEach times out',1100 [1101 /^Error: Timeout - Async function did not complete within 4000ms \(custom timeout\)/1102 ]1103 );1104 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1105 'suite it times out',1106 [1107 /^Error: Timeout - Async function did not complete within 6000ms \(custom timeout\)/1108 ]1109 );1110 jasmine.clock().tick(1);1111 realSetTimeout(done);1112 });1113 });1114 });1115 it('explicitly fails an async spec', function(done) {1116 var specDone = jasmine.createSpy('specDone');1117 env.addReporter({ specDone: specDone });1118 env.describe('failing', function() {1119 env.it('has a default message', function(innerDone) {1120 setTimeout(function() {1121 env.fail();1122 innerDone();1123 }, 1);1124 });1125 env.it('specifies a message', function(innerDone) {1126 setTimeout(function() {1127 env.fail('messy message');1128 innerDone();1129 }, 1);1130 });1131 env.it('fails via the done callback', function(innerDone) {1132 setTimeout(function() {1133 innerDone.fail('done failed');1134 }, 1);1135 });1136 env.it('has a message from an Error', function(innerDone) {1137 setTimeout(function() {1138 env.fail(new Error('error message'));1139 innerDone();1140 }, 1);1141 });1142 env.it('has a message from an Error to done', function(innerDone) {1143 setTimeout(function() {1144 innerDone(new Error('done error'));1145 }, 1);1146 });1147 });1148 env.execute(null, function() {1149 expect(specDone).toHaveFailedExpectationsForRunnable(1150 'failing has a default message',1151 ['Failed']1152 );1153 expect(specDone).toHaveFailedExpectationsForRunnable(1154 'failing specifies a message',1155 ['Failed: messy message']1156 );1157 expect(specDone).toHaveFailedExpectationsForRunnable(1158 'failing fails via the done callback',1159 ['Failed: done failed']1160 );1161 expect(specDone).toHaveFailedExpectationsForRunnable(1162 'failing has a message from an Error',1163 ['Failed: error message']1164 );1165 expect(specDone).toHaveFailedExpectationsForRunnable(1166 'failing has a message from an Error to done',1167 ['Failed: done error']1168 );1169 setTimeout(done);1170 });1171 });1172 describe('focused tests', function() {1173 it('should only run the focused tests', function(done) {1174 var calls = [];1175 env.describe('a suite', function() {1176 env.fit('is focused', function() {1177 calls.push('focused');1178 });1179 env.it('is not focused', function() {1180 calls.push('freakout');1181 });1182 });1183 env.execute(null, function() {1184 expect(calls).toEqual(['focused']);1185 done();1186 });1187 });1188 it('should only run focused suites', function(done) {1189 var calls = [];1190 env.fdescribe('a focused suite', function() {1191 env.it('is focused', function() {1192 calls.push('focused');1193 });1194 });1195 env.describe('a regular suite', function() {1196 env.it('is not focused', function() {1197 calls.push('freakout');1198 });1199 });1200 env.execute(null, function() {1201 expect(calls).toEqual(['focused']);1202 done();1203 });1204 });1205 it('should run focused tests inside an xdescribe', function(done) {1206 var reporter = jasmine.createSpyObj('fakeReporter', [1207 'jasmineStarted',1208 'suiteStarted',1209 'suiteDone',1210 'specStarted',1211 'specDone'1212 ]);1213 env.addReporter(reporter);1214 env.xdescribe('xd suite', function() {1215 env.fit('with a fit spec', function() {1216 env.expect(true).toBe(false);1217 });1218 });1219 env.execute(null, function() {1220 expect(reporter.jasmineStarted).toHaveBeenCalledWith({1221 totalSpecsDefined: 1,1222 order: jasmine.any(jasmineUnderTest.Order)1223 });1224 expect(reporter.specDone).toHaveBeenCalledWith(1225 jasmine.objectContaining({1226 description: 'with a fit spec',1227 status: 'failed'1228 })1229 );1230 done();1231 });1232 });1233 it('should run focused suites inside an xdescribe', function(done) {1234 var reporter = jasmine.createSpyObj('fakeReporter', [1235 'jasmineStarted',1236 'suiteStarted',1237 'suiteDone',1238 'specStarted',1239 'specDone'1240 ]);1241 env.addReporter(reporter);1242 env.xdescribe('xd suite', function() {1243 env.fdescribe('fd suite', function() {1244 env.it('with a spec', function() {1245 env.expect(true).toBe(false);1246 });1247 });1248 });1249 env.execute(null, function() {1250 expect(reporter.jasmineStarted).toHaveBeenCalledWith({1251 totalSpecsDefined: 1,1252 order: jasmine.any(jasmineUnderTest.Order)1253 });1254 expect(reporter.specDone).toHaveBeenCalledWith(1255 jasmine.objectContaining({1256 description: 'with a spec',1257 status: 'failed'1258 })1259 );1260 done();1261 });1262 });1263 });1264 it('should report as expected', function(done) {1265 var reporter = jasmine.createSpyObj('fakeReporter', [1266 'jasmineStarted',1267 'suiteStarted',1268 'suiteDone',1269 'specStarted',1270 'specDone'1271 ]);1272 env.addReporter(reporter);1273 env.describe('A Suite', function() {1274 env.it('with a top level spec', function() {1275 env.expect(true).toBe(true);1276 });1277 env.describe('with a nested suite', function() {1278 env.xit("with an x'ed spec", function() {1279 env.expect(true).toBe(true);1280 });1281 env.it('with a spec', function() {1282 env.expect(true).toBe(false);1283 });1284 });1285 env.describe('with only non-executable specs', function() {1286 env.it('is pending');1287 env.xit('is xed', function() {1288 env.expect(true).toBe(true);1289 });1290 });1291 });1292 env.execute(null, function() {1293 expect(reporter.jasmineStarted).toHaveBeenCalledWith({1294 totalSpecsDefined: 5,1295 order: jasmine.any(jasmineUnderTest.Order)1296 });1297 expect(reporter.specDone.calls.count()).toBe(5);1298 expect(reporter.specDone).toHaveBeenCalledWith(1299 jasmine.objectContaining({1300 description: 'with a top level spec',1301 status: 'passed'1302 })1303 );1304 expect(reporter.specDone).toHaveBeenCalledWith(1305 jasmine.objectContaining({1306 description: "with an x'ed spec",1307 status: 'pending'1308 })1309 );1310 expect(reporter.specDone).toHaveBeenCalledWith(1311 jasmine.objectContaining({1312 description: 'with a spec',1313 status: 'failed'1314 })1315 );1316 expect(reporter.specDone).toHaveBeenCalledWith(1317 jasmine.objectContaining({1318 description: 'is pending',1319 status: 'pending'1320 })1321 );1322 var suiteDone = reporter.suiteDone.calls.argsFor(0)[0];1323 expect(typeof suiteDone.duration).toBe('number');1324 var suiteResult = reporter.suiteStarted.calls.argsFor(0)[0];1325 expect(suiteResult.description).toEqual('A Suite');1326 done();1327 });1328 });1329 it('should report the random seed at the beginning and end of execution', function(done) {1330 var reporter = jasmine.createSpyObj('fakeReporter', [1331 'jasmineStarted',1332 'jasmineDone',1333 'suiteStarted',1334 'suiteDone',1335 'specStarted',1336 'specDone'1337 ]);1338 env.configure({ random: true, seed: '123456' });1339 env.addReporter(reporter);1340 env.configure({ random: true });1341 env.execute(null, function() {1342 expect(reporter.jasmineStarted).toHaveBeenCalled();1343 var startedArg = reporter.jasmineStarted.calls.argsFor(0)[0];1344 expect(startedArg.order.random).toEqual(true);1345 expect(startedArg.order.seed).toEqual('123456');1346 var doneArg = reporter.jasmineDone.calls.argsFor(0)[0];1347 expect(doneArg.order.random).toEqual(true);1348 expect(doneArg.order.seed).toEqual('123456');1349 done();1350 });1351 });1352 it('should report pending spec messages', function(done) {1353 var reporter = jasmine.createSpyObj('fakeReporter', ['specDone']);1354 env.addReporter(reporter);1355 env.it('will be pending', function() {1356 env.pending('with a message');1357 });1358 env.execute(null, function() {1359 var specStatus = reporter.specDone.calls.argsFor(0)[0];1360 expect(specStatus.status).toBe('pending');1361 expect(specStatus.pendingReason).toBe('with a message');1362 done();1363 });1364 });1365 it('should report pending spec messages from promise-returning functions', function(done) {1366 function StubPromise(fn) {1367 try {1368 fn();1369 } catch (e) {1370 this.exception = e;1371 }1372 }1373 StubPromise.prototype.then = function(resolve, reject) {1374 reject(this.exception);1375 };1376 var reporter = jasmine.createSpyObj('fakeReporter', ['specDone']);1377 env.addReporter(reporter);1378 env.it('will be pending', function() {1379 return new StubPromise(function() {1380 env.pending('with a message');1381 });1382 });1383 env.execute(null, function() {1384 var specStatus = reporter.specDone.calls.argsFor(0)[0];1385 expect(specStatus.status).toBe('pending');1386 expect(specStatus.pendingReason).toBe('with a message');1387 done();1388 });1389 });1390 it('should report using fallback reporter', function(done) {1391 var reporter = jasmine.createSpyObj('fakeReporter', [1392 'specDone',1393 'jasmineDone'1394 ]);1395 reporter.jasmineDone.and.callFake(function() {1396 expect(reporter.specDone).toHaveBeenCalled();1397 done();1398 });1399 env.provideFallbackReporter(reporter);1400 env.it('will be pending', function() {1401 env.pending('with a message');1402 });1403 env.execute();1404 });1405 it('should report xdescribes as expected', function(done) {1406 var reporter = jasmine.createSpyObj('fakeReporter', [1407 'jasmineStarted',1408 'suiteStarted',1409 'suiteDone',1410 'specStarted',1411 'specDone'1412 ]);1413 env.addReporter(reporter);1414 env.describe('A Suite', function() {1415 env.describe('nested', function() {1416 env.xdescribe('xd out', function() {1417 env.describe('nested again', function() {1418 env.it('with a spec', function() {1419 env.expect(true).toBe(false);1420 });1421 });1422 });1423 });1424 });1425 env.execute(null, function() {1426 expect(reporter.jasmineStarted).toHaveBeenCalledWith({1427 totalSpecsDefined: 1,1428 order: jasmine.any(jasmineUnderTest.Order)1429 });1430 expect(reporter.specDone).toHaveBeenCalledWith(1431 jasmine.objectContaining({ status: 'pending' })1432 );1433 expect(reporter.suiteDone).toHaveBeenCalledWith(1434 jasmine.objectContaining({ description: 'xd out', status: 'pending' })1435 );1436 expect(reporter.suiteDone.calls.count()).toBe(4);1437 done();1438 });1439 });1440 it('should be possible to get full name from a spec', function() {1441 var topLevelSpec, nestedSpec, doublyNestedSpec;1442 env.describe('my tests', function() {1443 topLevelSpec = env.it('are sometimes top level', function() {});1444 env.describe('are sometimes', function() {1445 nestedSpec = env.it('singly nested', function() {});1446 env.describe('even', function() {1447 doublyNestedSpec = env.it('doubly nested', function() {});1448 });1449 });1450 });1451 expect(topLevelSpec.getFullName()).toBe('my tests are sometimes top level');1452 expect(nestedSpec.getFullName()).toBe(1453 'my tests are sometimes singly nested'1454 );1455 expect(doublyNestedSpec.getFullName()).toBe(1456 'my tests are sometimes even doubly nested'1457 );1458 });1459 it('Custom equality testers should be per spec', function(done) {1460 var reporter = jasmine.createSpyObj('fakeReporter', ['specDone']);1461 env.addReporter(reporter);1462 env.configure({ random: false });1463 env.describe('testing custom equality testers', function() {1464 env.it('with a custom tester', function() {1465 env.addCustomEqualityTester(function(a, b) {1466 return true;1467 });1468 env.expect('a').toEqual('b');1469 });1470 env.it('without a custom tester', function() {1471 env.expect('a').toEqual('b');1472 });1473 });1474 env.execute(null, function() {1475 var firstSpecResult = reporter.specDone.calls.first().args[0],1476 secondSpecResult = reporter.specDone.calls.mostRecent().args[0];1477 expect(firstSpecResult.status).toEqual('passed');1478 expect(secondSpecResult.status).toEqual('failed');1479 done();1480 });1481 });1482 it('Custom equality testers should be per suite', function(done) {1483 var reporter = jasmine.createSpyObj('fakeReporter', ['specDone']);1484 env.addReporter(reporter);1485 env.configure({ random: false });1486 env.describe('testing custom equality testers', function() {1487 env.beforeAll(function() {1488 env.addCustomEqualityTester(function(a, b) {1489 return true;1490 });1491 });1492 env.it('with a custom tester', function() {1493 env.expect('a').toEqual('b');1494 });1495 env.it('with the same custom tester', function() {1496 env.expect('a').toEqual('b');1497 });1498 });1499 env.describe('another suite', function() {1500 env.it('without the custom tester', function() {1501 env.expect('a').toEqual('b');1502 });1503 });1504 env.execute(null, function() {1505 var firstSpecResult = reporter.specDone.calls.first().args[0],1506 secondSpecResult = reporter.specDone.calls.argsFor(0)[0],1507 thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];1508 expect(firstSpecResult.status).toEqual('passed');1509 expect(secondSpecResult.status).toEqual('passed');1510 expect(thirdSpecResult.status).toEqual('failed');1511 done();1512 });1513 });1514 it('Custom equality testers for toContain should be per spec', function(done) {1515 var reporter = jasmine.createSpyObj('fakeReporter', ['specDone']);1516 env.addReporter(reporter);1517 env.configure({ random: false });1518 env.describe('testing custom equality testers', function() {1519 env.it('with a custom tester', function() {1520 env.addCustomEqualityTester(function(a, b) {1521 return true;1522 });1523 env.expect(['a']).toContain('b');1524 });1525 env.it('without a custom tester', function() {1526 env.expect(['a']).toContain('b');1527 });1528 });1529 env.execute(null, function() {1530 var firstSpecResult = reporter.specDone.calls.first().args[0],1531 secondSpecResult = reporter.specDone.calls.mostRecent().args[0];1532 expect(firstSpecResult.status).toEqual('passed');1533 expect(secondSpecResult.status).toEqual('failed');1534 done();1535 });1536 });1537 it("produces an understandable error message when an 'expect' is used outside of a current spec", function(done) {1538 env.describe('A Suite', function() {1539 env.it('an async spec that is actually synchronous', function(1540 underTestCallback1541 ) {1542 underTestCallback();1543 });1544 expect(function() {1545 env.expect('a').toEqual('a');1546 }).toThrowError(/'expect' was used when there was no current spec/);1547 });1548 env.execute(null, done);1549 });1550 it('Custom equality testers for toContain should be per suite', function(done) {1551 var reporter = jasmine.createSpyObj('fakeReporter', ['specDone']);1552 env.addReporter(reporter);1553 env.configure({ random: false });1554 env.describe('testing custom equality testers', function() {1555 env.beforeAll(function() {1556 env.addCustomEqualityTester(function(a, b) {1557 return true;1558 });1559 });1560 env.it('with a custom tester', function() {1561 env.expect(['a']).toContain('b');1562 });1563 env.it('also with the custom tester', function() {1564 env.expect(['a']).toContain('b');1565 });1566 });1567 env.describe('another suite', function() {1568 env.it('without the custom tester', function() {1569 env.expect(['a']).toContain('b');1570 });1571 });1572 env.execute(null, function() {1573 var firstSpecResult = reporter.specDone.calls.first().args[0],1574 secondSpecResult = reporter.specDone.calls.argsFor(1)[0],1575 thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];1576 expect(firstSpecResult.status).toEqual('passed');1577 expect(secondSpecResult.status).toEqual('passed');1578 expect(thirdSpecResult.status).toEqual('failed');1579 done();1580 });1581 });1582 it('Custom matchers should be per spec', function(done) {1583 var matchers = {1584 toFoo: function() {}1585 };1586 env.describe('testing custom matchers', function() {1587 env.it('with a custom matcher', function() {1588 env.addMatchers(matchers);1589 expect(env.expect().toFoo).toBeDefined();1590 });1591 env.it('without a custom matcher', function() {1592 expect(env.expect().toFoo).toBeUndefined();1593 });1594 });1595 env.execute(null, done);1596 });1597 it('Custom matchers should be per suite', function(done) {1598 var matchers = {1599 toFoo: function() {}1600 };1601 env.describe('testing custom matchers', function() {1602 env.beforeAll(function() {1603 env.addMatchers(matchers);1604 });1605 env.it('with a custom matcher', function() {1606 expect(env.expect().toFoo).toBeDefined();1607 });1608 env.it('with the same custom matcher', function() {1609 expect(env.expect().toFoo).toBeDefined();1610 });1611 });1612 env.describe('another suite', function() {1613 env.it('no longer has the custom matcher', function() {1614 expect(env.expect().toFoo).not.toBeDefined();1615 });1616 });1617 env.execute(null, done);1618 });1619 it('throws an exception if you try to create a spy outside of a runnable', function(done) {1620 var obj = { fn: function() {} },1621 exception;1622 env.describe('a suite', function() {1623 try {1624 env.spyOn(obj, 'fn');1625 } catch (e) {1626 exception = e;1627 }1628 });1629 env.execute(null, function() {1630 expect(exception.message).toBe(1631 'Spies must be created in a before function or a spec'1632 );1633 done();1634 });1635 });1636 it('throws an exception if you try to add a matcher outside of a runnable', function(done) {1637 var obj = { fn: function() {} },1638 exception;1639 env.describe('a suite', function() {1640 try {1641 env.addMatchers({1642 myMatcher: function(actual, expected) {1643 return false;1644 }1645 });1646 } catch (e) {1647 exception = e;1648 }1649 });1650 env.execute(null, function() {1651 expect(exception.message).toBe(1652 'Matchers must be added in a before function or a spec'1653 );1654 done();1655 });1656 });1657 it('throws an exception if you try to add a custom equality outside of a runnable', function(done) {1658 var obj = { fn: function() {} },1659 exception;1660 env.describe('a suite', function() {1661 try {1662 env.addCustomEqualityTester(function(first, second) {1663 return true;1664 });1665 } catch (e) {1666 exception = e;1667 }1668 });1669 env.execute(null, function() {1670 expect(exception.message).toBe(1671 'Custom Equalities must be added in a before function or a spec'1672 );1673 done();1674 });1675 });1676 it('reports test properties on specs', function(done) {1677 var env = new jasmineUnderTest.Env(),1678 reporter = jasmine.createSpyObj('reporter', ['suiteDone', 'specDone']);1679 reporter.specDone.and.callFake(function(e) {1680 expect(e.properties).toEqual({ a: 'Bee' });1681 });1682 env.addReporter(reporter);1683 env.it('calls setSpecProperty', function() {1684 env.setSpecProperty('a', 'Bee');1685 });1686 env.execute(null, function() {1687 expect(reporter.specDone).toHaveBeenCalled();1688 done();1689 });1690 });1691 it('throws an exception if you try to setSpecProperty outside of a spec', function(done) {1692 var env = new jasmineUnderTest.Env(),1693 exception;1694 env.describe('a suite', function() {1695 env.it('a spec');1696 try {1697 env.setSpecProperty('a prop', 'val');1698 } catch (e) {1699 exception = e;1700 }1701 });1702 env.execute(null, function() {1703 expect(exception.message).toBe(1704 "'setSpecProperty' was used when there was no current spec"1705 );1706 done();1707 });1708 });1709 it('reports test properties on suites', function(done) {1710 var env = new jasmineUnderTest.Env(),1711 reporter = jasmine.createSpyObj('reporter', [1712 'jasmineDone',1713 'suiteDone',1714 'specDone'1715 ]);1716 reporter.suiteDone.and.callFake(function(e) {1717 expect(e.properties).toEqual({ b: 'Sweet' });1718 });1719 env.addReporter(reporter);1720 env.describe('calls setSuiteProperty', function() {1721 env.beforeEach(function() {1722 env.setSuiteProperty('b', 'Sweet');1723 });1724 env.it('a passing spec', function() {1725 expect.nothing();1726 });1727 });1728 env.execute(null, function() {1729 expect(reporter.suiteDone).toHaveBeenCalled();1730 done();1731 });1732 });1733 it('throws an exception if you try to setSuiteProperty outside of a suite', function(done) {1734 var env = new jasmineUnderTest.Env();1735 try {1736 env.setSuiteProperty('a', 'Bee');1737 } catch (e) {1738 expect(e.message).toBe(1739 "'setSuiteProperty' was used when there was no current suite"1740 );1741 done();1742 }1743 });1744 it('should associate errors thrown from async code with the correct runnable', function(done) {1745 var reporter = jasmine.createSpyObj('fakeReport', [1746 'suiteDone',1747 'specDone'1748 ]);1749 env.addReporter(reporter);1750 env.describe('async suite', function() {1751 env.afterAll(function(innerDone) {1752 setTimeout(function() {1753 throw new Error('suite');1754 }, 1);1755 }, 10);1756 env.it('spec', function() {});1757 });1758 env.describe('suite', function() {1759 env.it(1760 'async spec',1761 function(innerDone) {1762 setTimeout(function() {1763 throw new Error('spec');1764 }, 1);1765 },1766 101767 );1768 });1769 env.execute(null, function() {1770 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(1771 'async suite',1772 [1773 /^(((Uncaught )?(exception: )?Error: suite( thrown)?)|(suite thrown))$/1774 ]1775 );1776 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1777 'suite async spec',1778 [/^(((Uncaught )?(exception: )?Error: spec( thrown)?)|(spec thrown))$/]1779 );1780 done();1781 });1782 });1783 it("should throw on suites/specs/befores/afters nested in methods other than 'describe'", function(done) {1784 var reporter = jasmine.createSpyObj('reporter', ['suiteDone', 'specDone']);1785 env.addReporter(reporter);1786 env.describe('suite', function() {1787 env.it('describe', function() {1788 env.describe('inner suite', function() {});1789 });1790 env.it('xdescribe', function() {1791 env.xdescribe('inner suite', function() {});1792 });1793 env.it('fdescribe', function() {1794 env.fdescribe('inner suite', function() {});1795 });1796 });1797 env.describe('spec', function() {1798 env.it('it', function() {1799 env.it('inner spec', function() {});1800 });1801 env.it('xit', function() {1802 env.xit('inner spec', function() {});1803 });1804 env.it('fit', function() {1805 env.fit('inner spec', function() {});1806 });1807 });1808 env.describe('beforeAll', function() {1809 env.beforeAll(function() {1810 env.beforeAll(function() {});1811 });1812 env.it('spec', function() {});1813 });1814 env.describe('beforeEach', function() {1815 env.beforeEach(function() {1816 env.beforeEach(function() {});1817 });1818 env.it('spec', function() {});1819 });1820 env.describe('afterAll', function() {1821 env.afterAll(function() {1822 env.afterAll(function() {});1823 });1824 env.it('spec', function() {});1825 });1826 env.describe('afterEach', function() {1827 env.afterEach(function() {1828 env.afterEach(function() {});1829 });1830 env.it('spec', function() {});1831 });1832 env.execute(null, function() {1833 var msg = /\'.*\' should only be used in \'describe\' function/;1834 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1835 'suite describe',1836 [msg]1837 );1838 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1839 'suite xdescribe',1840 [msg]1841 );1842 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1843 'suite fdescribe',1844 [msg]1845 );1846 expect(reporter.specDone).toHaveFailedExpectationsForRunnable('spec it', [1847 msg1848 ]);1849 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1850 'spec xit',1851 [msg]1852 );1853 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1854 'spec fit',1855 [msg]1856 );1857 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(1858 'beforeAll',1859 [msg]1860 );1861 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1862 'beforeEach spec',1863 [msg]1864 );1865 expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable(1866 'afterAll',1867 [msg]1868 );1869 expect(reporter.specDone).toHaveFailedExpectationsForRunnable(1870 'afterEach spec',1871 [msg]1872 );1873 done();1874 });1875 });1876 it('reports errors that occur during loading', function(done) {1877 var global = {1878 setTimeout: function(fn, delay) {1879 setTimeout(fn, delay);1880 },1881 clearTimeout: function(fn, delay) {1882 clearTimeout(fn, delay);1883 },1884 onerror: function() {}1885 };1886 spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);1887 env.cleanup_();1888 env = new jasmineUnderTest.Env();1889 var reporter = jasmine.createSpyObj('reporter', [1890 'jasmineDone',1891 'suiteDone',1892 'specDone'1893 ]);1894 env.addReporter(reporter);1895 global.onerror(1896 'Uncaught SyntaxError: Unexpected end of input',1897 'borkenSpec.js',1898 42,1899 undefined,1900 { stack: 'a stack' }1901 );1902 global.onerror('Uncaught Error: ENOCHEESE');1903 env.execute(null, function() {1904 var e = reporter.jasmineDone.calls.argsFor(0)[0];1905 expect(e.failedExpectations).toEqual([1906 {1907 passed: false,1908 globalErrorType: 'load',1909 message: 'Uncaught SyntaxError: Unexpected end of input',1910 stack: 'a stack',1911 filename: 'borkenSpec.js',1912 lineno: 421913 },1914 {1915 passed: false,1916 globalErrorType: 'load',1917 message: 'Uncaught Error: ENOCHEESE',1918 stack: undefined,1919 filename: undefined,1920 lineno: undefined1921 }1922 ]);1923 done();1924 });1925 });1926 describe('If suppressLoadErrors: true was passed', function() {1927 it('does not install a global error handler during loading', function(done) {1928 var originalOnerror = jasmine.createSpy('original onerror');1929 var global = {1930 setTimeout: function(fn, delay) {1931 setTimeout(fn, delay);1932 },1933 clearTimeout: function(fn, delay) {1934 clearTimeout(fn, delay);1935 },1936 onerror: originalOnerror1937 };1938 spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);1939 var globalErrors = new jasmineUnderTest.GlobalErrors(global);1940 var onerror = jasmine.createSpy('onerror');1941 globalErrors.pushListener(onerror);1942 spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);1943 env.cleanup_();1944 env = new jasmineUnderTest.Env({ suppressLoadErrors: true });1945 var reporter = jasmine.createSpyObj('reporter', [1946 'jasmineDone',1947 'suiteDone',1948 'specDone'1949 ]);1950 env.addReporter(reporter);1951 global.onerror('Uncaught Error: ENOCHEESE');1952 env.execute(null, function() {1953 var e = reporter.jasmineDone.calls.argsFor(0)[0];1954 expect(e.failedExpectations).toEqual([]);1955 expect(originalOnerror).toHaveBeenCalledWith(1956 'Uncaught Error: ENOCHEESE'1957 );1958 done();1959 });1960 });1961 });1962 describe('Overall status in the jasmineDone event', function() {1963 describe('When everything passes', function() {1964 it('is "passed"', function(done) {1965 var reporter = jasmine.createSpyObj('reporter', [1966 'jasmineDone',1967 'suiteDone',1968 'specDone'1969 ]);1970 env.addReporter(reporter);1971 env.it('passes', function() {});1972 env.execute(null, function() {1973 var e = reporter.jasmineDone.calls.argsFor(0)[0];1974 expect(e.overallStatus).toEqual('passed');1975 done();1976 });1977 });1978 });1979 describe('When a spec fails', function() {1980 it('is "failed"', function(done) {1981 var reporter = jasmine.createSpyObj('reporter', [1982 'jasmineDone',1983 'suiteDone',1984 'specDone'1985 ]);1986 env.addReporter(reporter);1987 env.it('fails', function() {1988 env.expect(true).toBe(false);1989 });1990 env.execute(null, function() {1991 var e = reporter.jasmineDone.calls.argsFor(0)[0];1992 expect(e.overallStatus).toEqual('failed');1993 done();1994 });1995 });1996 });1997 describe('when spec has no expectations', function() {1998 var reporter;1999 beforeEach(function() {2000 reporter = jasmine.createSpyObj('reporter', [2001 'jasmineDone',2002 'suiteDone',2003 'specDone'2004 ]);2005 env.addReporter(reporter);2006 env.it('is a spec without any expectations', function() {2007 // does nothing, just a mock spec without expectations2008 });2009 });2010 it('should report "failed" status if "failSpecWithNoExpectations" is enabled', function(done) {2011 env.configure({ failSpecWithNoExpectations: true });2012 env.execute(null, function() {2013 var e = reporter.jasmineDone.calls.argsFor(0)[0];2014 expect(e.overallStatus).toEqual('failed');2015 done();2016 });2017 });2018 it('should report "passed" status if "failSpecWithNoExpectations" is disabled', function(done) {2019 env.configure({ failSpecWithNoExpectations: false });2020 env.execute(null, function() {2021 var e = reporter.jasmineDone.calls.argsFor(0)[0];2022 expect(e.overallStatus).toEqual('passed');2023 done();2024 });2025 });2026 });2027 describe('When a top-level beforeAll fails', function() {2028 it('is "failed"', function(done) {2029 var reporter = jasmine.createSpyObj('reporter', [2030 'jasmineDone',2031 'suiteDone',2032 'specDone'2033 ]);2034 env.addReporter(reporter);2035 env.beforeAll(function() {2036 throw new Error('nope');2037 });2038 env.it('does not run', function() {});2039 env.execute(null, function() {2040 var e = reporter.jasmineDone.calls.argsFor(0)[0];2041 expect(e.overallStatus).toEqual('failed');2042 done();2043 });2044 });2045 });2046 describe('When a suite beforeAll fails', function() {2047 it('is "failed"', function(done) {2048 var reporter = jasmine.createSpyObj('reporter', [2049 'jasmineDone',2050 'suiteDone',2051 'specDone'2052 ]);2053 env.addReporter(reporter);2054 env.describe('something', function() {2055 env.beforeAll(function() {2056 throw new Error('nope');2057 });2058 env.it('does not run', function() {});2059 });2060 env.execute(null, function() {2061 var e = reporter.jasmineDone.calls.argsFor(0)[0];2062 expect(e.overallStatus).toEqual('failed');2063 done();2064 });2065 });2066 });2067 describe('When a top-level afterAll fails', function() {2068 it('is "failed"', function(done) {2069 var reporter = jasmine.createSpyObj('reporter', [2070 'jasmineDone',2071 'suiteDone',2072 'specDone'2073 ]);2074 env.addReporter(reporter);2075 env.afterAll(function() {2076 throw new Error('nope');2077 });2078 env.it('does not run', function() {});2079 env.execute(null, function() {2080 var e = reporter.jasmineDone.calls.argsFor(0)[0];2081 expect(e.overallStatus).toEqual('failed');2082 done();2083 });2084 });2085 });2086 describe('When a suite afterAll fails', function() {2087 it('is "failed"', function(done) {2088 var reporter = jasmine.createSpyObj('reporter', [2089 'jasmineDone',2090 'suiteDone',2091 'specDone'2092 ]);2093 env.addReporter(reporter);2094 env.describe('something', function() {2095 env.afterAll(function() {2096 throw new Error('nope');2097 });2098 env.it('does not run', function() {});2099 });2100 env.execute(null, function() {2101 var e = reporter.jasmineDone.calls.argsFor(0)[0];2102 expect(e.overallStatus).toEqual('failed');2103 done();2104 });2105 });2106 });2107 describe('When there are load errors', function() {2108 it('is "failed"', function(done) {2109 var global = {2110 setTimeout: function(fn, delay) {2111 setTimeout(fn, delay);2112 },2113 clearTimeout: function(fn, delay) {2114 clearTimeout(fn, delay);2115 }2116 };2117 spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);2118 env.cleanup_();2119 env = new jasmineUnderTest.Env();2120 var reporter = jasmine.createSpyObj('reporter', [2121 'jasmineDone',2122 'suiteDone',2123 'specDone'2124 ]);2125 reporter.jasmineDone.and.callFake(function(e) {2126 expect(e.overallStatus).toEqual('failed');2127 });2128 env.addReporter(reporter);2129 env.it('passes', function() {});2130 global.onerror('Uncaught Error: ENOCHEESE');2131 env.execute(null, function() {2132 expect(reporter.jasmineDone).toHaveBeenCalled();2133 done();2134 });2135 });2136 });2137 describe('When there are no specs', function() {2138 it('is "incomplete"', function(done) {2139 var reporter = jasmine.createSpyObj('reporter', [2140 'jasmineDone',2141 'suiteDone',2142 'specDone'2143 ]);2144 env.addReporter(reporter);2145 env.execute(null, function() {2146 var e = reporter.jasmineDone.calls.argsFor(0)[0];2147 expect(e.overallStatus).toEqual('incomplete');2148 expect(e.incompleteReason).toEqual('No specs found');2149 done();2150 });2151 });2152 });2153 describe('When a spec is focused', function() {2154 it('is "incomplete"', function(done) {2155 var reporter = jasmine.createSpyObj('reporter', [2156 'jasmineDone',2157 'suiteDone',2158 'specDone'2159 ]);2160 env.addReporter(reporter);2161 env.fit('is focused', function() {});2162 env.execute(null, function(e) {2163 var e = reporter.jasmineDone.calls.argsFor(0)[0];2164 expect(e.overallStatus).toEqual('incomplete');2165 expect(e.incompleteReason).toEqual('fit() or fdescribe() was found');2166 done();2167 });2168 });2169 });2170 describe('When a suite is focused', function() {2171 it('is "incomplete"', function(done) {2172 var reporter = jasmine.createSpyObj('reporter', [2173 'jasmineDone',2174 'suiteDone',2175 'specDone'2176 ]);2177 env.addReporter(reporter);2178 env.fdescribe('something focused', function() {2179 env.it('does a thing', function() {});2180 });2181 env.execute(null, function() {2182 var e = reporter.jasmineDone.calls.argsFor(0)[0];2183 expect(e.overallStatus).toEqual('incomplete');2184 expect(e.incompleteReason).toEqual('fit() or fdescribe() was found');2185 done();2186 });2187 });2188 });2189 describe('When there are both failures and focused specs', function() {2190 it('is "failed"', function(done) {2191 var reporter = jasmine.createSpyObj('reporter', [2192 'jasmineDone',2193 'suiteDone',2194 'specDone'2195 ]);2196 env.addReporter(reporter);2197 env.fit('is focused', function() {2198 env.expect(true).toBe(false);2199 });2200 env.execute(null, function() {2201 var e = reporter.jasmineDone.calls.argsFor(0)[0];2202 expect(e.overallStatus).toEqual('failed');2203 expect(e.incompleteReason).toBeUndefined();2204 done();2205 });2206 });2207 });2208 });2209 it('should report deprecation warnings on the correct specs and suites', function(done) {2210 var reporter = jasmine.createSpyObj('reporter', [2211 'jasmineDone',2212 'suiteDone',2213 'specDone'2214 ]);2215 // prevent deprecation from being displayed, as well as letting us observe calls2216 spyOn(console, 'error');2217 env.addReporter(reporter);2218 env.deprecated('top level deprecation');2219 env.describe('suite', function() {2220 env.beforeAll(function() {2221 env.deprecated('suite level deprecation');2222 });2223 env.it('spec', function() {2224 env.deprecated('spec level deprecation');2225 });2226 });2227 env.execute(null, function() {2228 var result = reporter.jasmineDone.calls.argsFor(0)[0];2229 expect(result.deprecationWarnings).toEqual([2230 jasmine.objectContaining({ message: 'top level deprecation' })2231 ]);2232 /* eslint-disable-next-line no-console */2233 expect(console.error).toHaveBeenCalledWith(2234 'DEPRECATION: top level deprecation'2235 );2236 expect(reporter.suiteDone).toHaveBeenCalledWith(2237 jasmine.objectContaining({2238 fullName: 'suite',2239 deprecationWarnings: [2240 jasmine.objectContaining({ message: 'suite level deprecation' })2241 ]2242 })2243 );2244 /* eslint-disable-next-line no-console */2245 expect(console.error).toHaveBeenCalledWith(2246 'DEPRECATION: suite level deprecation (in suite: suite)'2247 );2248 expect(reporter.specDone).toHaveBeenCalledWith(2249 jasmine.objectContaining({2250 fullName: 'suite spec',2251 deprecationWarnings: [2252 jasmine.objectContaining({ message: 'spec level deprecation' })2253 ]2254 })2255 );2256 /* eslint-disable-next-line no-console */2257 expect(console.error).toHaveBeenCalledWith(2258 'DEPRECATION: spec level deprecation (in spec: suite spec)'2259 );2260 done();2261 });2262 });2263 it('should report deprecation stack with an error object', function(done) {2264 var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),2265 reporter = jasmine.createSpyObj('reporter', [2266 'jasmineDone',2267 'suiteDone',2268 'specDone'2269 ]),2270 topLevelError,2271 suiteLevelError,2272 specLevelError;2273 try {2274 throw new Error('top level deprecation');2275 } catch (err) {2276 topLevelError = err;2277 }2278 try {2279 throw new Error('suite level deprecation');2280 } catch (err) {2281 suiteLevelError = err;2282 }2283 try {2284 throw new Error('spec level deprecation');2285 } catch (err) {2286 specLevelError = err;2287 }2288 // prevent deprecation from being displayed2289 spyOn(console, 'error');2290 env.addReporter(reporter);2291 env.deprecated(topLevelError);2292 env.describe('suite', function() {2293 env.beforeAll(function() {2294 env.deprecated(suiteLevelError);2295 });2296 env.it('spec', function() {2297 env.deprecated(specLevelError);2298 });2299 });2300 env.execute(null, function() {2301 var result = reporter.jasmineDone.calls.argsFor(0)[0];2302 expect(result.deprecationWarnings).toEqual([2303 jasmine.objectContaining({2304 message: topLevelError.message,2305 stack: exceptionFormatter.stack(topLevelError)2306 })2307 ]);2308 expect(reporter.suiteDone).toHaveBeenCalledWith(2309 jasmine.objectContaining({2310 fullName: 'suite',2311 deprecationWarnings: [2312 jasmine.objectContaining({2313 message: suiteLevelError.message,2314 stack: exceptionFormatter.stack(suiteLevelError)2315 })2316 ]2317 })2318 );2319 expect(reporter.specDone).toHaveBeenCalledWith(2320 jasmine.objectContaining({2321 fullName: 'suite spec',2322 deprecationWarnings: [2323 jasmine.objectContaining({2324 message: specLevelError.message,2325 stack: exceptionFormatter.stack(specLevelError)2326 })2327 ]2328 })2329 );2330 done();2331 });2332 });2333 it('supports async matchers', function(done) {2334 jasmine.getEnv().requirePromises();2335 var specDone = jasmine.createSpy('specDone'),2336 suiteDone = jasmine.createSpy('suiteDone'),2337 jasmineDone = jasmine.createSpy('jasmineDone');2338 env.addReporter({2339 specDone: specDone,2340 suiteDone: suiteDone,2341 jasmineDone: jasmineDone2342 });2343 function fail(innerDone) {2344 var resolve;2345 // eslint-disable-next-line compat/compat2346 var p = new Promise(function(res, rej) {2347 resolve = res;2348 });2349 env2350 .expectAsync(p)2351 .toBeRejected()2352 .then(innerDone);2353 resolve();2354 }2355 env.afterAll(fail);2356 env.describe('a suite', function() {2357 env.afterAll(fail);2358 env.it('has an async failure', fail);2359 });2360 env.execute(null, function() {2361 var result = jasmineDone.calls.argsFor(0)[0];2362 expect(result.failedExpectations).toEqual([2363 jasmine.objectContaining({2364 message: 'Expected [object Promise] to be rejected.'2365 })2366 ]);2367 expect(specDone).toHaveBeenCalledWith(2368 jasmine.objectContaining({2369 description: 'has an async failure',2370 failedExpectations: [2371 jasmine.objectContaining({2372 message: 'Expected [object Promise] to be rejected.'2373 })2374 ]2375 })2376 );2377 expect(suiteDone).toHaveBeenCalledWith(2378 jasmine.objectContaining({2379 description: 'a suite',2380 failedExpectations: [2381 jasmine.objectContaining({2382 message: 'Expected [object Promise] to be rejected.'2383 })2384 ]2385 })2386 );2387 done();2388 });2389 });2390 it('provides custom equality testers to async matchers', function(done) {2391 if (jasmine.getEnv().skipBrowserFlake) {2392 jasmine.getEnv().skipBrowserFlake();2393 }2394 jasmine.getEnv().requirePromises();2395 var specDone = jasmine.createSpy('specDone');2396 env.addReporter({ specDone: specDone });2397 env.it('has an async failure', function() {2398 env.addCustomEqualityTester(function() {2399 return true;2400 });2401 var p = Promise.resolve('something'); // eslint-disable-line compat/compat2402 return env.expectAsync(p).toBeResolvedTo('something else');2403 });2404 env.execute(null, function() {2405 expect(specDone).toHaveBeenCalledWith(2406 jasmine.objectContaining({2407 description: 'has an async failure',2408 failedExpectations: []2409 })2410 );2411 done();2412 });2413 });2414 it('includes useful stack frames in async matcher failures', function(done) {2415 jasmine.getEnv().requirePromises();2416 var specDone = jasmine.createSpy('specDone');2417 env.addReporter({ specDone: specDone });2418 env.it('has an async failure', function() {2419 env.addCustomEqualityTester(function() {2420 return true;2421 });2422 var p = Promise.resolve(); // eslint-disable-line compat/compat2423 return env.expectAsync(p).toBeRejected();2424 });2425 env.execute(null, function() {2426 expect(specDone).toHaveBeenCalledWith(2427 jasmine.objectContaining({2428 failedExpectations: [2429 jasmine.objectContaining({2430 stack: jasmine.stringMatching('EnvSpec.js')2431 })2432 ]2433 })2434 );2435 done();2436 });2437 });2438 it('reports an error when an async expectation occurs after the spec finishes', function(done) {2439 jasmine.getEnv().requirePromises();2440 var resolve,2441 jasmineDone = jasmine.createSpy('jasmineDone'),2442 // eslint-disable-next-line compat/compat2443 promise = new Promise(function(res) {2444 resolve = res;2445 });2446 env.configure({ random: false });2447 env.describe('a suite', function() {2448 env.it('does not wait', function() {2449 // Note: we intentionally don't return the result of each expectAsync.2450 // This causes the spec to finish before the expectations are evaluated.2451 env.expectAsync(promise).toBeResolved();2452 env.expectAsync(promise).toBeResolvedTo('something else');2453 });2454 });2455 env.it('another spec', function(done) {2456 // This is here to make sure that the async expectation evaluates2457 // before the Jasmine under test finishes, especially on Safari 8 and 9.2458 setTimeout(done, 10);2459 });2460 env.addReporter({2461 specDone: function() {2462 resolve();2463 },2464 jasmineDone: jasmineDone2465 });2466 env.execute(null, function() {2467 var result = jasmineDone.calls.argsFor(0)[0];2468 expect(result.failedExpectations).toEqual([2469 jasmine.objectContaining({2470 passed: false,2471 globalErrorType: 'lateExpectation',2472 message:2473 'Spec "a suite does not wait" ran a "toBeResolved" expectation ' +2474 'after it finished.\n' +2475 'Did you forget to return or await the result of expectAsync?',2476 matcherName: 'toBeResolved'2477 }),2478 jasmine.objectContaining({2479 passed: false,2480 globalErrorType: 'lateExpectation',2481 message:2482 'Spec "a suite does not wait" ran a "toBeResolvedTo" expectation ' +2483 'after it finished.\n' +2484 "Message: \"Expected a promise to be resolved to 'something else' " +2485 'but it was resolved to undefined."\n' +2486 'Did you forget to return or await the result of expectAsync?',2487 matcherName: 'toBeResolvedTo'2488 })2489 ]);2490 done();2491 });2492 });2493 it('reports an error when an async expectation occurs after the suite finishes', function(done) {2494 jasmine.getEnv().requirePromises();2495 var resolve,2496 jasmineDone = jasmine.createSpy('jasmineDone'),2497 // eslint-disable-next-line compat/compat2498 promise = new Promise(function(res) {2499 resolve = res;2500 });2501 env.configure({ random: false });2502 env.describe('a suite', function() {2503 env.afterAll(function() {2504 // Note: we intentionally don't return the result of expectAsync.2505 // This causes the suite to finish before the expectations are evaluated.2506 env.expectAsync(promise).toBeResolved();2507 });2508 env.it('is a spec', function() {});2509 });2510 env.it('another spec', function(done) {2511 // This is here to make sure that the async expectation evaluates2512 // before the Jasmine under test finishes, especially on Safari 8 and 9.2513 setTimeout(done, 10);2514 });2515 env.addReporter({2516 suiteDone: function() {2517 resolve();2518 },2519 jasmineDone: jasmineDone2520 });2521 env.execute(null, function() {2522 var result = jasmineDone.calls.argsFor(0)[0];2523 expect(result.failedExpectations).toEqual([2524 jasmine.objectContaining({2525 passed: false,2526 globalErrorType: 'lateExpectation',2527 message:2528 'Suite "a suite" ran a "toBeResolved" expectation ' +2529 'after it finished.\n' +2530 'Did you forget to return or await the result of expectAsync?',2531 matcherName: 'toBeResolved'2532 })2533 ]);2534 done();2535 });2536 });2537 it('supports asymmetric equality testers that take a matchersUtil', function(done) {2538 var env = new jasmineUnderTest.Env();2539 env.it('spec using custom asymmetric equality tester', function() {2540 var customEqualityFn = function(a, b) {2541 if (a === 2 && b === 'two') {2542 return true;2543 }2544 };2545 var arrayWithFirstElement = function(sample) {2546 return {2547 asymmetricMatch: function(actual, matchersUtil) {2548 return matchersUtil.equals(sample, actual[0]);2549 }2550 };2551 };2552 env.addCustomEqualityTester(customEqualityFn);2553 env.expect(['two']).toEqual(arrayWithFirstElement(2));2554 });2555 var specExpectations = function(result) {2556 expect(result.status).toEqual('passed');2557 };2558 env.addReporter({ specDone: specExpectations });2559 env.execute(null, done);2560 });2561 describe('The promise returned by #execute', function() {2562 beforeEach(function() {2563 this.savedInterval = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL;2564 });2565 afterEach(function() {2566 jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = this.savedInterval;2567 });2568 it('is resolved after reporter events are dispatched', function() {2569 jasmine.getEnv().requirePromises();2570 var reporter = jasmine.createSpyObj('reporter', [2571 'specDone',2572 'suiteDone',2573 'jasmineDone'2574 ]);2575 env.addReporter(reporter);2576 env.describe('suite', function() {2577 env.it('spec', function() {});2578 });2579 return env.execute(null).then(function() {2580 expect(reporter.specDone).toHaveBeenCalled();2581 expect(reporter.suiteDone).toHaveBeenCalled();2582 expect(reporter.jasmineDone).toHaveBeenCalled();2583 });2584 });2585 it('is resolved after the stack is cleared', function(done) {2586 jasmine.getEnv().requirePromises();2587 var realClearStack = jasmineUnderTest.getClearStack(2588 jasmineUnderTest.getGlobal()2589 ),2590 clearStackSpy = jasmine2591 .createSpy('clearStack')2592 .and.callFake(realClearStack);2593 spyOn(jasmineUnderTest, 'getClearStack').and.returnValue(clearStackSpy);2594 // Create a new env that has the clearStack defined above2595 env.cleanup_();2596 env = new jasmineUnderTest.Env();2597 env.describe('suite', function() {2598 env.it('spec', function() {});2599 });2600 env.execute(null).then(function() {2601 expect(clearStackSpy).toHaveBeenCalled(); // (many times)2602 clearStackSpy.calls.reset();2603 setTimeout(function() {2604 expect(clearStackSpy).not.toHaveBeenCalled();2605 done();2606 });2607 });2608 });2609 it('is resolved after QueueRunner timeouts are cleared', function() {2610 jasmine.getEnv().requirePromises();2611 var setTimeoutSpy = spyOn(2612 jasmineUnderTest.getGlobal(),2613 'setTimeout'2614 ).and.callThrough();2615 var clearTimeoutSpy = spyOn(2616 jasmineUnderTest.getGlobal(),2617 'clearTimeout'2618 ).and.callThrough();2619 jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 123456; // a distinctive value2620 env = new jasmineUnderTest.Env();2621 env.describe('suite', function() {2622 env.it('spec', function() {});2623 });2624 return env.execute(null).then(function() {2625 var timeoutIds = setTimeoutSpy.calls2626 .all()2627 .filter(function(call) {2628 return call.args[1] === 123456;2629 })2630 .map(function(call) {2631 return call.returnValue;2632 });2633 expect(timeoutIds.length).toBeGreaterThan(0);2634 timeoutIds.forEach(function(timeoutId) {2635 expect(clearTimeoutSpy).toHaveBeenCalledWith(timeoutId);2636 });2637 });2638 });2639 it('is resolved even if specs fail', function() {2640 jasmine.getEnv().requirePromises();2641 env.describe('suite', function() {2642 env.it('spec', function() {2643 env.expect(true).toBe(false);2644 });2645 });2646 return expectAsync(env.execute(null)).toBeResolved();2647 });2648 });2649 describe('The optional callback argument to #execute', function() {2650 beforeEach(function() {2651 this.savedInterval = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL;2652 });2653 afterEach(function() {2654 jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = this.savedInterval;2655 });2656 it('is called after reporter events are dispatched', function(done) {2657 var reporter = jasmine.createSpyObj('reporter', [2658 'specDone',2659 'suiteDone',2660 'jasmineDone'2661 ]);2662 env.addReporter(reporter);2663 env.describe('suite', function() {2664 env.it('spec', function() {});2665 });2666 env.execute(null, function() {2667 expect(reporter.specDone).toHaveBeenCalled();2668 expect(reporter.suiteDone).toHaveBeenCalled();2669 expect(reporter.jasmineDone).toHaveBeenCalled();2670 done();2671 });2672 });2673 it('is called after the stack is cleared', function(done) {2674 var realClearStack = jasmineUnderTest.getClearStack(2675 jasmineUnderTest.getGlobal()2676 ),2677 clearStackSpy = jasmine2678 .createSpy('clearStack')2679 .and.callFake(realClearStack);2680 spyOn(jasmineUnderTest, 'getClearStack').and.returnValue(clearStackSpy);2681 // Create a new env that has the clearStack defined above2682 env.cleanup_();2683 env = new jasmineUnderTest.Env();2684 env.describe('suite', function() {2685 env.it('spec', function() {});2686 });2687 env.execute(null, function() {2688 expect(clearStackSpy).toHaveBeenCalled(); // (many times)2689 clearStackSpy.calls.reset();2690 setTimeout(function() {2691 expect(clearStackSpy).not.toHaveBeenCalled();2692 done();2693 });2694 });2695 });2696 it('is called after QueueRunner timeouts are cleared', function(done) {2697 var setTimeoutSpy = spyOn(2698 jasmineUnderTest.getGlobal(),2699 'setTimeout'2700 ).and.callThrough();2701 var clearTimeoutSpy = spyOn(2702 jasmineUnderTest.getGlobal(),2703 'clearTimeout'2704 ).and.callThrough();2705 jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 123456; // a distinctive value2706 env = new jasmineUnderTest.Env();2707 env.describe('suite', function() {2708 env.it('spec', function() {});2709 });2710 env.execute(null, function() {2711 var timeoutIds = setTimeoutSpy.calls2712 .all()2713 .filter(function(call) {2714 return call.args[1] === 123456;2715 })2716 .map(function(call) {2717 return call.returnValue;2718 });2719 expect(timeoutIds.length).toBeGreaterThan(0);2720 timeoutIds.forEach(function(timeoutId) {2721 expect(clearTimeoutSpy).toHaveBeenCalledWith(timeoutId);2722 });2723 done();2724 });2725 });2726 });...

Full Screen

Full Screen

suite-done.spec.js

Source:suite-done.spec.js Github

copy

Full Screen

1const suiteDone = require('../../src/zephyr-reporter-functions/suite-done');2describe(`suiteDone()`, () => {3 let self;4 beforeEach(() => {5 self = {6 disabled: false,7 globals: {8 executionId: '4343',9 status: '1'10 },11 zephyrService: {},12 onCompleteDefer: {13 fulfill: () => true,14 },15 specPromises: []16 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('suite1', function() {2 it('spec1', function() {3 expect(true).toBe(true);4 });5});6describe('suite2', function() {7 it('spec2', function() {8 expect(true).toBe(true);9 });10});11{12 "print": function() {},13 "junitreport": {14 }15}16var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');17var jasmineReporters = require('jasmine-reporters');18exports.config = {19 onPrepare: function() {20 jasmine.getEnv().addReporter(21 new jasmineReporters.JUnitXmlReporter({22 })23 );24 }25};26 at Object.<anonymous> (/Users/username/automation/test/helpers/jasmine-json-reporter.js:11:17)27 at Module._compile (module.js:652:30)28 at Object.Module._extensions..js (module.js:663:10)29 at Module.load (module.js:565:32)30 at tryModuleLoad (module.js:505:12)31 at Function.Module._load (module.js:497:3)32 at Module.require (module.js:596:17)

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("Suite", function() {2 it("Test1", function() {3 expect(true).toBe(true);4 });5 it("Test2", function() {6 expect(true).toBe(true);7 });8});9jasmine.getEnv().addReporter({10 suiteDone: function(result) {11 console.log("Suite: " + result.description + " was " + result.status);12 }13});14jasmine.getEnv().execute();15Your name to display (optional):16Your name to display (optional):17describe("Suite", function() {18 it("Test1", function() {19 expect(true).toBe(true);20 });21 it("Test2", function() {22 expect(true).toBe(true);23 });24});25jasmine.getEnv().addReporter({26 suiteDone: function(result) {27 console.log("Suite: " + result.description + " was " + result.status);28 }29});30jasmine.getEnv().execute();31Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var jasmine = require('jasmine-node');2jasmine.executeSpecsInFolder(__dirname, function(runner, log){3 var rootSuite = runner.suites()[0];4 rootSuite.suiteDone(function(suite){5 console.log(suite.description + ' finished');6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('TestSuite', function() {2 it('Test1', function() {3 expect(browser.getTitle()).toEqual('AngularJS — Superheroic JavaScript MVW Framework');4 });5 it('Test2', function() {6 expect(browser.getTitle()).toEqual('AngularJS — Superheroic JavaScript MVW Framework');7 });8 it('Test3', function() {9 expect(browser.getTitle()).toEqual('AngularJS — Superheroic JavaScript MVW Framework');10 });11});12jasmine.getEnv().addReporter({13 suiteDone: function(result) {14 console.log('Suite ' + result.description + ' was ' + result.status);15 }16});17describe('TestSuite', function() {18 describe('TestSuite1', function() {19 it('Test1', function() {20 expect(browser.getTitle()).toEqual('AngularJS — Superheroic JavaScript MVW Framework');21 });22 it('Test2', function() {23 expect(browser.getTitle()).toEqual('AngularJS — Superheroic JavaScript MVW Framework');24 });25 it('Test3', function() {26 expect(browser.getTitle()).toEqual('AngularJS — Superheroic JavaScript MVW Framework');27 });28 });29});30jasmine.getEnv().addReporter({31 suiteDone: function(result) {32 console.log('Suite ' + result.description + ' was ' + result.status);33 }34});35describe('TestSuite', function() {36 describe('TestSuite1', function() {37 it('Test1', function() {38 expect(browser.getTitle()).toEqual('AngularJS — Superheroic JavaScript MVW Framework');39 });40 it('Test2', function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('suite1', function() {2 it('test1', function() {3 });4 it('test2', function() {5 });6});7describe('suite2', function() {8 it('test3', function() {9 });10 it('test4', function() {11 });12});13describe('suite3', function() {14 it('test5', function() {15 });16 it('test6', function() {17 });18});19describe('suite4', function() {20 it('test7', function() {21 });22 it('test8', function() {23 });24});25describe('suite5', function() {26 it('test9', function() {27 });28 it('test10', function() {29 });30});31describe('suite6', function() {32 it('test11', function() {33 });34 it('test12', function() {35 });36});37describe('suite7', function() {38 it('test13', function() {39 });40 it('test14', function() {41 });42});43describe('suite8', function() {44 it('test15', function() {45 });46 it('test16', function() {47 });48});49describe('suite9', function() {50 it('test17', function() {51 });52 it('test18', function() {53 });54});55describe('suite10', function() {56 it('test19', function() {57 });58 it('test20

Full Screen

Using AI Code Generation

copy

Full Screen

1var rootSuite = jasmine.getEnv().currentRunner().topSuite();2rootSuite.suiteDone = function(result) {3 console.log("Suite Done");4 console.log(result);5};6rootSuite.specDone = function(result) {7 console.log("Spec Done");8 console.log(result);9};10rootSuite.specStarted = function(result) {11 console.log("Spec Started");12 console.log(result);13};14rootSuite.suiteStarted = function(result) {15 console.log("Suite Started");16 console.log(result);17};18rootSuite.suiteDone = function(result) {19 console.log("Suite Done");20 console.log(result);21};22rootSuite.specDone = function(result) {23 console.log("Spec Done");24 console.log(result);25};26rootSuite.specStarted = function(result) {27 console.log("Spec Started");28 console.log(result);29};30rootSuite.suiteStarted = function(result) {31 console.log("Suite Started");32 console.log(result);33};34rootSuite.suiteDone = function(result) {35 console.log("Suite Done");36 console.log(result);37};38rootSuite.specDone = function(result) {39 console.log("Spec Done");40 console.log(result);41};42rootSuite.specStarted = function(result) {43 console.log("Spec Started");44 console.log(result);45};46rootSuite.suiteStarted = function(result) {47 console.log("Suite Started");48 console.log(result);49};50rootSuite.suiteDone = function(result) {51 console.log("Suite Done");52 console.log(result);53};54rootSuite.specDone = function(result) {55 console.log("Spec Done");56 console.log(result);57};58rootSuite.specStarted = function(result) {59 console.log("Spec

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Suite', function() {2 describe('suite', function() {3 it('test', function() {4 expect(true).toBe(true);5 });6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Root Suite', function () {2 beforeEach(function () {3 });4 afterEach(function () {5 });6 describe('Suite 1', function () {7 it('Test 1', function () {8 });9 });10 describe('Suite 2', function () {11 it('Test 2', function () {12 });13 });14 suiteDone(function () {15 });16});17describe('Root Suite', function () {18 beforeEach(function () {19 });20 afterEach(function () {21 });22 describe('Suite 1', function () {23 it('Test 1', function () {24 });25 suiteDone(function () {26 });27 });28 describe('Suite 2', function () {29 it('Test 2', function () {30 });31 suiteDone(function () {32 });33 });34});35describe('Root Suite', function () {36 beforeEach(function () {37 });38 afterEach(function () {39 });40 describe('Suite 1', function () {41 it('Test 1', function () {42 });43 });44 describe('Suite 2', function () {45 it('Test 2', function () {46 });47 });48 suiteDone(function () {49 });50});51describe('Root Suite', function () {52 beforeEach(function () {53 });54 afterEach(function () {55 });56 describe('Suite 1', function () {57 it('Test 1', function () {58 });59 suiteDone(function () {60 });61 });62 describe('Suite 2', function () {63 it('Test 2', function () {64 });65 suiteDone(function () {66 });67 });68});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful