Completed
Push — master ( aa59a9...9ba8bc )
by Alejandro
27s queued 10s
created

test/settings/services/SettingsService.test.js   A

Complexity

Total Complexity 8
Complexity/F 1.14

Size

Lines of Code 46
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 30
mnd 1
bc 1
fnc 7
dl 0
loc 46
rs 10
bpm 0.1428
cpm 1.1428
noi 5
c 0
b 0
f 0
1
import SettingsService from '../../../src/settings/services/SettingsService';
2
3
describe('SettingsService', () => {
4
  const settings = { foo: 'bar' };
5
  const createService = (withSettings = true) => {
6
    const storageMock = {
7
      set: jest.fn(),
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
8
      get: jest.fn(() => withSettings ? settings : undefined),
9
    };
10
    const service = new SettingsService(storageMock);
11
12
    return [ service, storageMock ];
13
  };
14
15
  afterEach(jest.resetAllMocks);
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
16
17
  describe('loadSettings', () => {
18
    it.each([
0 ignored issues
show
Bug introduced by
The variable it seems to be never declared. If this is a global, consider adding a /** global: it */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
19
      [ false, {}],
20
      [ true, settings ],
21
    ])('returns result if found in storage', (withSettings, expectedResult) => {
22
      const [ service, storageMock ] = createService(withSettings);
23
24
      const result = service.loadSettings();
25
26
      expect(result).toEqual(expectedResult);
27
      expect(storageMock.get).toHaveBeenCalledTimes(1);
28
      expect(storageMock.set).not.toHaveBeenCalled();
29
    });
30
  });
31
32
  describe('updateSettings', () => {
33
    it.each([
0 ignored issues
show
Bug introduced by
The variable it seems to be never declared. If this is a global, consider adding a /** global: it */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
34
      [ false, { hi: 'goodbye' }, { hi: 'goodbye' }],
35
      [ true, { hi: 'goodbye' }, { foo: 'bar', hi: 'goodbye' }],
36
      [ true, { foo: 'goodbye' }, { foo: 'goodbye' }],
37
    ])('appends provided data to existing settings', (withSettings, settingsToUpdate, expectedResult) => {
38
      const [ service, storageMock ] = createService(withSettings);
39
40
      service.updateSettings(settingsToUpdate);
41
42
      expect(storageMock.get).toHaveBeenCalledTimes(1);
43
      expect(storageMock.set).toHaveBeenCalledWith(expect.anything(), expectedResult);
0 ignored issues
show
Bug introduced by
The variable expect seems to be never declared. If this is a global, consider adding a /** global: expect */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
44
    });
45
  });
46
});
47