Open Pasupathi-Rajamanickam opened 6 years ago
I did window.XMLHttpRequest = false;
on top of my test. But need a better way to solve this problem
You don't have to use yaml.load()
actually. You could just fetch the raw yaml data yourself in whichever way you want (like, with fs.readFile()
in node?) and parse it with yaml.parse()
. That should give you more control
You can just mock the whole YamlJs:
jest.mock(
'yamljs',
function createYamlJsMock() {
return {parse: jest.fn()};
}
);
import YAML from 'yamljs';
describe('Foo', function testFoo() {
it('Bar', function testBar() {
(new MyYamlReader())->loadAndParse("dummy");
// call in MyYamlReader class: YAML.parse
expect(YAML.parse).toHaveBeenCalled();
YAML.parse.mockReset(); // reset, because kinda global mocked ;)
});
});
I'm trying to write backend test cases attached with yml, when the yml file tries to load, getting
NetworkError
The reason behind this is, jest havingwindow
object with the execution so ymljs trying to access file usingxhr
how to solve this issue?