How test Quasar plugins in Jest
doox911-opensource opened this issue · comments
Custom function with Notify:
import { Notify } from 'quasar';
export interface NotifyProps {
color?: 'dark' | 'negative' | 'positive';
message?: string;
timeout?: number;
}
export function notify({ color = 'dark', message, timeout = 5000 }: NotifyProps) {
if (!message || !message.length) {
return;
}
Notify.create({
actions: [{ icon: 'close', color: 'white' }],
color,
message,
position: 'bottom-right',
progress: true,
timeout,
});
}
Test:
import { describe, it } from '@jest/globals';
import { installQuasarPlugin } from '@quasar/quasar-app-extension-testing-unit-jest';
import { Notify } from 'quasar';
import { notify } from './lib/notify';
installQuasarPlugin({ plugins: { Notify } });
describe('Test', () => {
it('Success', async () => {
notify({ message: 'Успешно' });
});
});
Expected: everything is ok.
Result:
packege.json
:
{
"private": true,
"scripts": {
// some scripts
},
"dependencies": {
"@quasar/extras": "^1.15.5",
"axios": "^0.21.1",
"chart.js": "^4.2.1",
"core-js": "^3.6.5",
"jwt-decode": "^3.1.2",
"pinia": "^2.0.11",
"quasar": "^2.10.0",
"vue": "^3.0.0",
"vue-chartjs": "^5.2.0",
"vue-router": "^4.0.0"
},
"devDependencies": {
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@mocks-server/main": "^4.0.0",
"@mocks-server/plugin-openapi": "^2.0.0",
"@openapitools/openapi-generator-cli": "^2.5.2",
"@quasar/app-webpack": "^3.6.2",
"@quasar/quasar-app-extension-testing": "^2.0.4",
"@quasar/quasar-app-extension-testing-e2e-cypress": "^4.2.2",
"@quasar/quasar-app-extension-testing-unit-jest": "^3.0.0-beta.5",
"@types/node": "^12.20.21",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"@vue/test-utils": "^2.2.0",
"dotenv": "^16.0.3",
"eslint": "^8.10.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-cypress": "^2.11.3",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jest": "^27.1.3",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-vue": "^9.0.0",
"husky": "^8.0.0",
"jest": "^29.2.2",
"lint-staged": "^13.1.0",
"majestic": "^1.8.1"
},
"browserslist": [
"last 10 Chrome versions",
"last 10 Firefox versions",
"last 4 Edge versions",
"last 7 Safari versions",
"last 8 Android versions",
"last 8 ChromeAndroid versions",
"last 8 FirefoxAndroid versions",
"last 10 iOS versions",
"last 5 Opera versions"
],
"engines": {
"node": ">= 12.22.1",
"npm": ">= 6.13.4",
"yarn": ">= 1.21.1"
}
}