Files
001code-html--cocos/scratch-vm/test/unit/tw_translate.js
2026-09-07 09:55:36 +08:00

29 lines
925 B
JavaScript

const {test} = require('tap');
// Simulate the network being down or filtered
// Run this before fetch-with-timeout.js is gets loaded.
global.fetch = () => Promise.reject(new Error('Simulated network error'));
const Scratch3TranslateBlocks = require('../../src/extensions/scratch3_translate/index');
// Node 21 and later defines a navigator object, but we want to override that for the test
Object.defineProperty(global, 'navigator', {
value: {
language: 'en-US'
}
});
// Translate tries to access AbortController from window, but does not require it to exist.
global.window = {};
test('translate returns original string on network error', t => {
t.plan(1);
const extension = new Scratch3TranslateBlocks();
extension.getTranslate({WORDS: 'My message 123123', LANGUAGE: 'es'})
.then(message => {
t.equal(message, 'My message 123123');
t.end();
});
});