How to use arrayOfArbitraryFns method in Jasmine-core

Best JavaScript code snippet using jasmine-core

Run Jasmine-core automation tests on LambdaTest cloud grid

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

CompleteOnFirstErrorSkipPolicySpec.js

Source: CompleteOnFirstErrorSkipPolicySpec.js Github

copy
1describe('CompleteOnFirstErrorSkipPolicy', function() {
2  describe('#skipTo', function() {
3    describe('Before anything has errored', function() {
4      it('returns the next index', function() {
5        const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
6          arrayOfArbitraryFns(4),
7          4
8        );
9        expect(policy.skipTo(1)).toEqual(2);
10      });
11    });
12
13    describe('After something has errored', function() {
14      it('skips non cleanup fns', function() {
15        const fns = arrayOfArbitraryFns(4);
16        fns[2].type = arbitraryCleanupType();
17        fns[3].type = arbitraryCleanupType();
18        const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(fns);
19
20        policy.fnErrored(0);
21        expect(policy.skipTo(0)).toEqual(2);
22        expect(policy.skipTo(2)).toEqual(3);
23        expect(policy.skipTo(3)).toEqual(4);
24      });
25
26      for (const type of ['afterEach', 'specCleanup', 'afterAll']) {
27        it(`does not skip ${type} fns`, function() {
28          const fns = arrayOfArbitraryFns(2);
29          fns[1].type = type;
30          const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
31            fns
32          );
33
34          policy.fnErrored(0);
35          expect(policy.skipTo(0)).toEqual(1);
36        });
37      }
38
39      describe('When the error was in a beforeEach fn', function() {
40        it('runs cleanup fns defined by the current and containing suites', function() {
41          const parentSuite = { description: 'parentSuite' };
42          const suite = { description: 'suite', parentSuite };
43          const fns = [
44            {
45              suite: suite
46            },
47            {
48              fn: () => {}
49            },
50            {
51              fn: () => {},
52              suite: suite,
53              type: arbitraryCleanupType()
54            },
55            {
56              fn: () => {},
57              suite: parentSuite,
58              type: arbitraryCleanupType()
59            }
60          ];
61          const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
62            fns
63          );
64
65          policy.fnErrored(0);
66          expect(policy.skipTo(0)).toEqual(2);
67          expect(policy.skipTo(2)).toEqual(3);
68        });
69
70        it('skips cleanup fns defined by nested suites', function() {
71          const parentSuite = { description: 'parentSuite' };
72          const suite = { description: 'suite', parentSuite };
73          const fns = [
74            {
75              fn: () => {},
76              type: 'beforeEach',
77              suite: parentSuite
78            },
79            {
80              fn: () => {}
81            },
82            {
83              fn: () => {},
84              suite: suite,
85              type: arbitraryCleanupType()
86            },
87            {
88              fn: () => {},
89              suite: parentSuite,
90              type: arbitraryCleanupType()
91            }
92          ];
93          const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
94            fns
95          );
96
97          policy.fnErrored(0);
98          expect(policy.skipTo(0)).toEqual(3);
99        });
100      });
101
102      it('does not skip cleanup fns that have no suite, such as the spec complete fn', function() {
103        const fns = [
104          { fn: () => {} },
105          {
106            fn: () => {},
107            type: arbitraryCleanupType()
108          }
109        ];
110        const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(fns);
111
112        policy.fnErrored(0);
113        expect(policy.skipTo(0)).toEqual(1);
114      });
115    });
116  });
117
118  function arrayOfArbitraryFns(n) {
119    const result = [];
120
121    for (let i = 0; i < n; i++) {
122      result.push({ fn: () => {} });
123    }
124
125    return result;
126  }
127
128  function arbitraryCleanupType() {
129    return 'specCleanup';
130  }
131});
132
Full Screen

SkipAfterBeforeAllErrorPolicySpec.js

Source: SkipAfterBeforeAllErrorPolicySpec.js Github

copy
1describe('SkipAfterBeforeAllErrorPolicy', function() {
2  describe('#skipTo', function() {
3    describe('When nothing has errored', function() {
4      it('does not skip anything', function() {
5        const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
6          arrayOfArbitraryFns(4)
7        );
8
9        expect(policy.skipTo(0)).toEqual(1);
10        expect(policy.skipTo(1)).toEqual(2);
11        expect(policy.skipTo(2)).toEqual(3);
12        expect(policy.skipTo(3)).toEqual(4);
13      });
14    });
15
16    describe('When anything but a beforeAll has errored', function() {
17      it('does not skip anything', function() {
18        const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
19          arrayOfArbitraryFns(4)
20        );
21
22        policy.fnErrored(0);
23        expect(policy.skipTo(0)).toEqual(1);
24        policy.fnErrored(1);
25        expect(policy.skipTo(1)).toEqual(2);
26        policy.fnErrored(2);
27        expect(policy.skipTo(2)).toEqual(3);
28        policy.fnErrored(3);
29        expect(policy.skipTo(3)).toEqual(4);
30      });
31    });
32
33    describe('When a beforeAll has errored', function() {
34      it('skips subsequent functions other than afterAll', function() {
35        const suite = {};
36        const fns = [
37          { type: 'beforeAll', fn: () => {}, suite },
38          { fn: () => {} },
39          { fn: () => {} },
40          { type: 'afterAll', fn: () => {} },
41          { type: 'afterAll', fn: () => {} }
42        ];
43        const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(fns);
44
45        policy.fnErrored(0);
46        expect(policy.skipTo(0)).toEqual(3);
47        expect(policy.skipTo(3)).toEqual(4);
48      });
49    });
50  });
51
52  describe('#fnErrored', function() {
53    describe('When the fn is a beforeAll', function() {
54      it("sets the suite's hadBeforeAllFailure property to true", function() {
55        const suite = {};
56        const fns = [{ type: 'beforeAll', fn: () => {}, suite }];
57        const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(fns);
58
59        policy.fnErrored(0);
60
61        expect(suite.hadBeforeAllFailure).toBeTrue();
62      });
63    });
64
65    describe('When the fn is not a beforeAll', function() {
66      it('does not try to access the suite, which is probably not there', function() {
67        const fns = [{ fn: () => {} /* no suite */ }];
68        const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(fns);
69
70        expect(() => policy.fnErrored(0)).not.toThrow();
71      });
72    });
73  });
74});
75
76function arrayOfArbitraryFns(n) {
77  const result = [];
78
79  for (let i = 0; i < n; i++) {
80    result.push({ fn: () => {} });
81  }
82
83  return result;
84}
85
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Jasmine-core on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)