@@ -15,20 +15,6 @@ import { LogMock } from '../helper/logMock';
15
15
import * as Utils from '../../src/utils' ;
16
16
17
17
// https://github.com/facebook/jest/issues/5023
18
- // https://medium.com/@masonlgoetz /mock-static-class-methods-in-jest-1ceda967b47f
19
- // https://gist.github.com/virgs/d9c50e878fc69832c01f8085f2953f12
20
- jest . mock ( '../../src/integrations' , ( ) => {
21
- const mockedInstances = {
22
- Integrations : jest . fn ( ) . mockImplementation ( ( ) => {
23
- return {
24
- integrate : jest . fn ( ) ,
25
- } ;
26
- } ) ,
27
- } ;
28
- // @ts -ignore
29
- mockedInstances . Integrations . onRegisteredExternalIntegration = jest . fn ( ) ;
30
- return mockedInstances ;
31
- } ) ;
32
18
jest . mock ( '../../src/runtime' , ( ) => {
33
19
return {
34
20
Runtime : jest . fn ( ) ,
@@ -44,12 +30,34 @@ jest.mock('../../src/storages', () => {
44
30
Storages : jest . fn ( ) ,
45
31
} ;
46
32
} ) ;
33
+
34
+ // https://gist.github.com/virgs/d9c50e878fc69832c01f8085f2953f12
35
+ // https://medium.com/@masonlgoetz /mock-static-class-methods-in-jest-1ceda967b47f
36
+ jest . mock ( '../../src/integrations' , ( ) => {
37
+ const mockedInstances = {
38
+ // https://jestjs.io/docs/mock-function-api#mockfnmockimplementationfn
39
+ Integrations : jest . fn ( ) . mockImplementation ( ( ) => {
40
+ return {
41
+ integrate : jest . fn ( ) ,
42
+ hasIntegration : jest . fn ( ) ,
43
+ } ;
44
+ } ) ,
45
+ } ;
46
+ // @ts -ignore
47
+ mockedInstances . Integrations . onRegisteredExternalIntegration = jest . fn ( ) ;
48
+ return mockedInstances ;
49
+ } ) ;
50
+
47
51
jest . mock ( '../../src/storages/storage' ) ;
48
52
jest . mock ( '../../src/collection' ) ;
49
53
jest . mock ( '../../src/computed' ) ;
50
- // Can't mock State because mocks get instantiated before everything else
51
- // -> I got the good old not loaded Object error https://github.com/kentcdodds/how-jest-mocking-works
52
- // jest.mock("../../src/state/index");
54
+
55
+ // https://github.com/facebook/jest/issues/5023
56
+ jest . mock ( '../../src/state' , ( ) => {
57
+ return {
58
+ State : jest . fn ( ) ,
59
+ } ;
60
+ } ) ;
53
61
54
62
describe ( 'Agile Tests' , ( ) => {
55
63
const RuntimeMock = Runtime as jest . MockedClass < typeof Runtime > ;
@@ -84,6 +92,7 @@ describe('Agile Tests', () => {
84
92
expect ( agile . config ) . toStrictEqual ( {
85
93
waitForMount : true ,
86
94
} ) ;
95
+ expect ( agile . key ) . toBeUndefined ( ) ;
87
96
expect ( IntegrationsMock ) . toHaveBeenCalledWith ( agile ) ;
88
97
// expect(agile.integrations).toBeInstanceOf(Integrations); // Because 'Integrations' is completely overwritten with a mock
89
98
expect ( RuntimeMock ) . toHaveBeenCalledWith ( agile ) ;
@@ -113,12 +122,14 @@ describe('Agile Tests', () => {
113
122
timestamp : true ,
114
123
} ,
115
124
bindGlobal : true ,
125
+ key : 'jeff' ,
116
126
} ) ;
117
127
118
128
// Check if Agile properties got instantiated properly
119
129
expect ( agile . config ) . toStrictEqual ( {
120
130
waitForMount : false ,
121
131
} ) ;
132
+ expect ( agile . key ) . toBe ( 'jeff' ) ;
122
133
expect ( IntegrationsMock ) . toHaveBeenCalledWith ( agile ) ;
123
134
// expect(agile.integrations).toBeInstanceOf(Integrations); // Because 'Integrations' is completely overwritten with a mock
124
135
expect ( RuntimeMock ) . toHaveBeenCalledWith ( agile ) ;
@@ -358,6 +369,10 @@ describe('Agile Tests', () => {
358
369
} ) ;
359
370
360
371
describe ( 'hasStorage function tests' , ( ) => {
372
+ beforeEach ( ( ) => {
373
+ agile . storages . hasStorage = jest . fn ( ) ;
374
+ } ) ;
375
+
361
376
it ( 'should check if Agile has any registered Storage' , ( ) => {
362
377
agile . hasStorage ( ) ;
363
378
0 commit comments