/ packages / string-templates / test / vm.spec.ts
vm.spec.ts
 1  jest.mock("../src/utilities", () => {
 2    const utilities = jest.requireActual("../src/utilities")
 3    return {
 4      ...utilities,
 5      isBackendService: jest.fn().mockReturnValue(true),
 6    }
 7  })
 8  
 9  import { defaultJSSetup, processStringSync, encodeJSBinding } from "../src"
10  import { isBackendService } from "../src/utilities"
11  
12  const mockedBackendService = jest.mocked(isBackendService)
13  
14  const binding = encodeJSBinding("return 1")
15  describe("confirm VM is available when expected and when not", () => {
16    it("shouldn't have JS available in a backend service by default", () => {
17      defaultJSSetup()
18      const result = processStringSync(binding, {})
19      // shouldn't process at all
20      expect(result).toBe(binding)
21    })
22  
23    it("should have JS available in frontend environments", () => {
24      mockedBackendService.mockReturnValue(false)
25      defaultJSSetup()
26      const result = processStringSync(binding, {})
27      expect(result).toBe(1)
28    })
29  })