🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@telefonica/living-apps-core-jest

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@telefonica/living-apps-core-jest

Mocks for testing laSdk calls with Jest

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
1
Maintainers
4
Weekly downloads
 
Created
Source

npm version

@telefonica/living-apps-core-jest

Mocks for testing laSdk calls with Jest

Installation

npm install --save-dev @telefonica/living-apps-core-jest

Import @telefonica/living-apps-core-jest once (for instance in your tests setup file) and you're good to go:

// In your own jest.setup.js (or any other name)
import '@telefonica/living-apps-core-jest';
// In jest.config.js add (if you haven't already)
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'];

You will also need to include your setup file in your `tsconfig.json`` if you haven't already:

  // In tsconfig.json
  "include": [
    ...
    "./jest-setup.ts"
  ],

Examples

test('your test', async () => {
  laSdk.telefonicaApi.get.mockResolvedValueOnce({
    value: 42,
  });

  const result = await someFunctionThatUsesGet();

  expect(result).toEqual({ value: 42 });
});
test('your test', async () => {
  render(<YourComponent />);

  expect(laSdk.focus).toHaveBeenCalledWith('some-element');
});
test('your test', async () => {
  render(<GenericWorldController {...} />);

  expect(laSdk.getMakerContents).toHaveBeenCalledTimes(1);
  expect(laSdk.getMakerContents).toHaveBeenCalledWith('YOUR SCREEN NAME');

Mocked Values

All the values from laSdk are set to the "most falsy" value possible that honor the type definitions. Except functions which are all jest.fn() functions; meaning:

typevalueexample
functionjest.fn()laSdk.http.get
booleanfalselaSdk.video.isPlaying
numberNaNlaSdk.video.duration
string''laSdk.video.src
NullablenulllaSdk.video.videoSessionId

There are a few exceptions:

  • laSdk.KEYS are the actual keys, we decided there was no drawback in populating KEYS with the real values. Even in this mocking library.
  • Honoring @telefonica/living-apps-core-web-types there are some strings that are specifically defined, in those cases we choose one from those instead of the empty string; example: laSdk.locale #=> 'es-ES'

Caveats

  • This package is executing a beforeEach() with the following mock setup (if this setup cause any trouble please contact with the team):
laSdk.persistenceRead() => Promise<void>

laSdk.getMakerContents() => Promise<{
  status: 200,
  json: {
    id: '__mocked_layout_id__',
    customType: 'layout_text',
    question: '',
    background: {},
    suggestions: [], s
  },
}>

Keywords

jest

FAQs

Package last updated on 21 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts