импорт * как (жасмин шпион) не доступен для записи - PullRequest
0 голосов
/ 14 ноября 2018

После обновления до babel 7.1.5 мои тесты не выполняются, когда я использую импорт * как.

test.spec.js

import * as Helper from "../../../../src/renderer/modules/Helper";

describe('Testing', () => {
    it('Should import correctly', () => {
        console.log(Helper.test()) // a
        spyOn(Helper, 'test').and.returnValue('b');
    });
});

Helper.js

function test() {
    return 'a'
}

export {test}

ERROR

'Upgrade.spec.js (7:8)', 'a'

Error: <spyOn> : test is not declared writable or has no setter
Usage: spyOn(<object>, <methodName>)
    at <Jasmine>
    at UserContext.it (webpack:///./test/unit/specs/renderer/Upgrade.spec.js?:7:5)
    at <Jasmine>

1 Ответ

0 голосов
/ 21 февраля 2019

source: Можно ли настроить модули webpack 4 так, чтобы Jasmine мог шпионить за их членами?

Есть spyOnProperty, который позволяет обрабатывать свойство только для чтения, устанавливая аргумент accessType в'get'.

Ваша установка будет выглядеть как

import * as mod from 'my/module';
//...
const funcSpy = jasmine.createSpy('myFunc').and.returnValue('myMockReturnValue');
spyOnProperty(mod, 'myFunc', 'get').and.returnValue(funcSpy);
...