@@ -3,7 +3,7 @@ import {JSDOM} from "jsdom";
33import { PuzzleJs } from "../src/puzzle" ;
44import { Core } from "../src/core" ;
55import { createPageLibConfiguration } from "./mock" ;
6- import sinon from "sinon" ;
6+ import sinon , { SinonStub } from "sinon" ;
77import { AssetHelper } from "../src/assetHelper" ;
88import * as faker from "faker" ;
99import { IPageLibAsset , IPageLibConfiguration , IPageLibDependency } from "../src/types" ;
@@ -22,17 +22,20 @@ declare global {
2222export interface Global {
2323 document : Document ;
2424 window : Window ;
25+ fetch : any ;
2526}
2627
2728declare var global : Global ;
2829
2930describe ( 'Module - Core' , ( ) => {
3031 beforeEach ( ( ) => {
31- global . window = ( new JSDOM ( `` , { runScripts : "outside-only" } ) ) . window ;
32+ global . window = ( new JSDOM ( `` , { runScripts : "outside-only" } ) ) . window ;
33+ global . fetch = sandbox . stub ( ) . resolves ( { json : ( ) => { } } ) ;
3234 } ) ;
3335
3436 afterEach ( ( ) => {
3537 delete global . window ;
38+ delete global . fetch ;
3639 PuzzleJs . clearListeners ( ) ;
3740 sandbox . verifyAndRestore ( ) ;
3841 ( Core as any ) . _pageConfiguration = undefined ;
@@ -210,14 +213,15 @@ describe('Module - Core', () => {
210213 fragmentContainer . setAttribute ( 'puzzle-fragment' , 'test' ) ;
211214 global . window . document . body . appendChild ( fragmentContainer ) ;
212215
213- const stubFetchGatewayFragment = sandbox . stub ( Core as any , "fetchGatewayFragment" ) . resolves ( ) ;
216+ const fetchStub = global . fetch as SinonStub ;
214217 const stubAsyncRenderResponse = sandbox . stub ( Core as any , "asyncRenderResponse" ) . resolves ( ) ;
215218
216219 Core . config ( JSON . stringify ( config ) ) ;
217220 await Core . renderAsyncFragment ( 'test' ) ;
218221 await Core . renderAsyncFragment ( 'test' ) ;
219-
220- expect ( stubFetchGatewayFragment . calledOnce ) . to . eq ( true ) ;
222+
223+ expect ( fetchStub . calledOnce ) . to . eq ( true ) ;
224+ expect ( fetchStub . getCall ( 0 ) . lastArg . headers ) . to . haveOwnProperty ( "originalurl" ) ;
221225 expect ( stubAsyncRenderResponse . calledOnce ) . to . eq ( true ) ;
222226 } ) ;
223227} ) ;
0 commit comments