Jest не может издеваться над окном, когда бежишь из Gulp - PullRequest
0 голосов
/ 29 февраля 2020

У меня есть модульный тест, который отлично работает, когда я запускаю Jest (v24.8.0) из командной строки, но не выполняется, когда проект тестируется из Gulp.

Ошибка при запуске из Gulp:

    window property does not exist

  14 |     test.only('finds the burl using ancestorOrigins when there is no parent frame', () => {
  15 |       const windowMock = new WindowMock;
> 16 |       const windowSpy = jest.spyOn(windowMock, "window", "get");
     |                              ^
  17 |       windowSpy.mockImplementation(() => ({
  18 |         location: {
  19 |           ancestorOrigins: [],

  at ModuleMockerClass._spyOnProperty (node_modules/jest-mock/build/index.js:899:13)
  at Object.test.only (src/__tests__/js/com/tm/util/IFrameData.test.js:16:30)

И модульный тест, который не проходит:

test('finds the burl using ancestorOrigins when there is no parent frame', () => {
  const windowSpy = jest.spyOn(global, "window", "get");
  windowSpy.mockImplementation(() => ({
    location: {
      ancestorOrigins: [],
      href: burl,
    }
  }));
  expect(IFrameData.detect(null, blankResult)).toStrictEqual({count: 0, burl: burl, rurl: null});
});

Любая идея, почему это пройдет при запуске из командной строки, но не пройден в сценарии сборки?

...