mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-05 19:41:42 +08:00
test(Notify): update test cases
This commit is contained in:
parent
4b340477af
commit
1a63d586b1
@ -52,14 +52,14 @@ function Notify(options) {
|
||||
function defaultOptions() {
|
||||
return {
|
||||
type: 'danger',
|
||||
message: '',
|
||||
color: undefined,
|
||||
background: undefined,
|
||||
duration: 3000,
|
||||
className: '',
|
||||
message: '',
|
||||
onClose: null,
|
||||
onClick: null,
|
||||
onOpened: null,
|
||||
duration: 3000,
|
||||
className: '',
|
||||
background: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,13 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`create a notify 1`] = `<div class="van-popup van-popup--top van-notify van-notify--danger" style="transition-duration: 0.2s; z-index: 2001;" name="van-popup-slide-top">test</div>`;
|
||||
|
||||
exports[`notify disappear 1`] = `<div class="van-popup van-popup--top van-notify van-notify--danger" style="transition-duration: 0.2s; z-index: 2001; color: red; background: blue;" name="van-popup-slide-top">test</div>`;
|
||||
|
||||
exports[`notify disappear 2`] = `<div class="van-popup van-popup--top van-notify van-notify--danger" style="transition-duration: 0.2s; z-index: 2001; color: red; background: blue; display: none;" name="van-popup-slide-top">test</div>`;
|
||||
|
||||
exports[`notify disappear 3`] = `<div class="van-popup van-popup--top van-notify van-notify--danger" style="transition-duration: 0.2s; z-index: 2002;" name="van-popup-slide-top">text2</div>`;
|
||||
|
||||
exports[`notify disappear 4`] = `<div class="van-popup van-popup--top van-notify van-notify--danger" style="transition-duration: 0.2s; z-index: 2002; display: none;" name="van-popup-slide-top">text2</div>`;
|
||||
|
||||
exports[`type prop 1`] = `<div class="van-popup van-popup--top van-notify van-notify--primary" style="transition-duration: 0.2s; z-index: 2001;" name="van-popup-slide-top">test</div>`;
|
14
src/notify/test/__snapshots__/index.spec.js.snap
Normal file
14
src/notify/test/__snapshots__/index.spec.js.snap
Normal file
@ -0,0 +1,14 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`should render Notify correctly 1`] = `
|
||||
<div
|
||||
class="van-popup van-popup--top van-notify van-notify--danger van-popup-slide-top-enter-active van-popup-slide-top-enter-from"
|
||||
style="z-index: 2001; transition-duration: 0.2s;"
|
||||
transitionappear="false"
|
||||
>
|
||||
|
||||
test
|
||||
|
||||
<!---->
|
||||
</div>
|
||||
`;
|
@ -1,71 +0,0 @@
|
||||
import Notify from '..';
|
||||
import { later } from '../../../test';
|
||||
|
||||
test('create a notify', async () => {
|
||||
// should not cause error when call clear before show notify
|
||||
Notify.clear();
|
||||
|
||||
const notify = Notify('test');
|
||||
|
||||
await later();
|
||||
expect(notify.$el.outerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('type prop', async () => {
|
||||
const notify = Notify({
|
||||
message: 'test',
|
||||
type: 'primary',
|
||||
});
|
||||
|
||||
await later();
|
||||
expect(notify.$el.outerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('notify disappear', async () => {
|
||||
const onClose = jest.fn();
|
||||
const notify = Notify({
|
||||
message: 'test',
|
||||
color: 'red',
|
||||
background: 'blue',
|
||||
duration: 10,
|
||||
onClose,
|
||||
});
|
||||
|
||||
await later();
|
||||
expect(notify.$el.outerHTML).toMatchSnapshot();
|
||||
|
||||
await later(20);
|
||||
expect(notify.$el.outerHTML).toMatchSnapshot();
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
|
||||
Notify({
|
||||
message: 'text2',
|
||||
duration: 0,
|
||||
});
|
||||
|
||||
await later();
|
||||
expect(notify.$el.outerHTML).toMatchSnapshot();
|
||||
|
||||
Notify.clear();
|
||||
await later();
|
||||
expect(notify.$el.outerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('set default options', () => {
|
||||
Notify.setDefaultOptions({ duration: 1000 });
|
||||
expect(Notify().duration).toEqual(1000);
|
||||
Notify.resetDefaultOptions();
|
||||
expect(Notify().duration).toEqual(3000);
|
||||
Notify.clear();
|
||||
});
|
||||
|
||||
test('onClick prop', async () => {
|
||||
const onClick = jest.fn();
|
||||
const notify = Notify({
|
||||
message: 'test',
|
||||
onClick,
|
||||
});
|
||||
|
||||
notify.$el.click();
|
||||
expect(onClick).toHaveBeenCalled();
|
||||
});
|
70
src/notify/test/index.spec.js
Normal file
70
src/notify/test/index.spec.js
Normal file
@ -0,0 +1,70 @@
|
||||
import { createApp } from 'vue';
|
||||
import Notify from '..';
|
||||
import NotifyComponent from '../Notify';
|
||||
import { later } from '../../../test';
|
||||
import { trigger } from '../../utils';
|
||||
|
||||
test('should not throw error if calling clear method before render notify', () => {
|
||||
Notify.clear();
|
||||
});
|
||||
|
||||
test('should render Notify correctly', async () => {
|
||||
Notify('test');
|
||||
await later();
|
||||
expect(document.querySelector('.van-notify')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should add "van-notify--success" class when type is success', async () => {
|
||||
Notify({
|
||||
message: 'test',
|
||||
type: 'success',
|
||||
});
|
||||
|
||||
await later();
|
||||
const notify = document.querySelector('.van-notify');
|
||||
expect(notify.classList.contains('van-notify--success')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('should register component to app', () => {
|
||||
const app = createApp();
|
||||
app.use(Notify);
|
||||
expect(app.component(NotifyComponent.name)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('should change default duration after calling setDefaultOptions method', () => {
|
||||
Notify.setDefaultOptions({ duration: 1000 });
|
||||
expect(Notify.currentOptions.duration).toEqual(1000);
|
||||
Notify.resetDefaultOptions();
|
||||
expect(Notify.currentOptions.duration).toEqual(3000);
|
||||
});
|
||||
|
||||
test('should reset to default duration after calling resetDefaultOptions method', () => {
|
||||
Notify.setDefaultOptions({ duration: 1000 });
|
||||
Notify.resetDefaultOptions();
|
||||
expect(Notify.currentOptions.duration).toEqual(3000);
|
||||
});
|
||||
|
||||
test('should call onClose option when closing', async () => {
|
||||
const onClose = jest.fn();
|
||||
Notify({
|
||||
message: 'test',
|
||||
onClose,
|
||||
duration: 1,
|
||||
});
|
||||
|
||||
await later(20);
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('should call onClick option when clicked', async () => {
|
||||
const onClick = jest.fn();
|
||||
Notify({
|
||||
message: 'test',
|
||||
onClick,
|
||||
});
|
||||
|
||||
await later();
|
||||
const notify = document.querySelector('.van-notify');
|
||||
trigger(notify, 'click');
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user