Browse Source

Update tests

typed-command-runs
Artur Arseniev 5 months ago
parent
commit
5141e06e1b
  1. 2
      packages/core/package.json
  2. 2
      packages/core/test/specs/commands/index.ts
  3. 15
      packages/core/test/specs/commands/view/Fullscreen.ts
  4. 2
      packages/core/test/specs/grapesjs/index.ts
  5. 4
      packages/core/test/types/commandRegistries.ts
  6. 18
      packages/core/test/types/tsconfig.json

2
packages/core/package.json

@ -69,7 +69,7 @@
"build:mjs": "cross-env BUILD_MODULE=true node node_modules/grapesjs-cli/dist/cli.js build --dts='skip' --patch=false --targets=\"defaults\"",
"build:css": "sass src/styles/scss/main.scss dist/css/grapes.min.css --no-source-map --style=compressed --load-path=node_modules",
"ts:build": "node node_modules/grapesjs-cli/dist/cli.js build --dts='only' --patch=false",
"ts:check": "tsc -p test/types/tsconfig.json",
"ts:check": "tsc --noEmit --esModuleInterop dist/index.d.ts",
"start": "cross-env NODE_ENV=development run-p start:*",
"start:js": "node node_modules/grapesjs-cli/dist/cli.js serve",
"start:css": "npm run build:css -- --watch",

2
packages/core/test/specs/commands/index.ts

@ -41,7 +41,7 @@ describe('Commands', () => {
obj.add('test', comm);
expect(obj.has('test')).toBe(true);
expect(Object.keys(obj.getAll()).length).toBe(len + 1);
expect(obj.get('test')!.test).toEqual('test');
expect((obj.get('test') as any).test).toEqual('test');
});
test('Default commands after loadDefaultCommands', () => {

15
packages/core/test/specs/commands/view/Fullscreen.ts

@ -3,16 +3,21 @@ import Editor from '../../../../src/editor';
describe('Fullscreen command', () => {
let editor: Editor;
let container: HTMLElement & { requestFullscreen: jest.Mock };
let container: HTMLElement;
let requestFullscreen: jest.Mock<Promise<void>, []>;
let isFullscreen: boolean;
let exitFullscreen: jest.Mock;
beforeEach(() => {
isFullscreen = false;
container = document.createElement('div') as HTMLElement & { requestFullscreen: jest.Mock };
container.requestFullscreen = jest.fn(() => {
requestFullscreen = jest.fn(async () => {
isFullscreen = true;
});
container = document.createElement('div');
Object.defineProperty(container, 'requestFullscreen', {
configurable: true,
value: requestFullscreen,
});
exitFullscreen = jest.fn(() => {
isFullscreen = false;
});
@ -42,7 +47,7 @@ describe('Fullscreen command', () => {
expect(editor.Commands.get('fullscreen')).toBeInstanceOf(CommandFullscreen);
editor.runCommand('core:fullscreen');
expect(container.requestFullscreen).toHaveBeenCalledTimes(1);
expect(requestFullscreen).toHaveBeenCalledTimes(1);
expect(addSpy).toHaveBeenCalledWith('fullscreenchange', expect.any(Function));
editor.stopCommand('core:fullscreen');
@ -50,7 +55,7 @@ describe('Fullscreen command', () => {
expect(removeSpy).toHaveBeenCalledWith('fullscreenchange', expect.any(Function));
editor.runCommand('fullscreen', { target: container });
expect(container.requestFullscreen).toHaveBeenCalledTimes(2);
expect(requestFullscreen).toHaveBeenCalledTimes(2);
editor.stopCommand('fullscreen');
expect(exitFullscreen).toHaveBeenCalledTimes(2);

2
packages/core/test/specs/grapesjs/index.ts

@ -606,7 +606,7 @@ describe('GrapesJS', () => {
config.plugins = [pluginName];
editor = grapesjs.init(config);
expect(editor.Commands.get('export-template')!.test).toEqual(1);
expect((editor.Commands.get('export-template') as any).test).toEqual(1);
});
describe('usePlugin', () => {

4
packages/core/test/types/commandRegistries.ts

@ -1,4 +1,4 @@
import type { Editor } from 'grapesjs';
import type { Editor } from '../../src';
interface MyCommandOptions {
value: number;
@ -12,7 +12,7 @@ interface MyCommandStopOptions {
reason: string;
}
declare module 'grapesjs' {
declare module '../../src' {
interface CommandRegistryRun {
'my:command': (options: MyCommandOptions) => MyCommandResult;
'my:stateless': () => number;

18
packages/core/test/types/tsconfig.json

@ -1,18 +0,0 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"strict": true,
"module": "esnext",
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"noEmit": true,
"baseUrl": "../..",
"paths": {
"grapesjs": ["dist/index.d.ts"]
}
},
"files": ["commandRegistries.ts"]
}
Loading…
Cancel
Save