Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit07bc5da

Browse files
author
Valentin Viennot
committed
add tests for copy button
1 parent7d92dee commit07bc5da

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed
Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
11
import{shallow}from'vue-test-utils';
22
importCaCodeSnippetfrom'./CaCodeSnippet.vue';
33

4+
jest.useFakeTimers();
5+
46
describe('CaCodeSnippet',()=>{
7+
letwrapper;
8+
9+
beforeEach(()=>{
10+
wrapper=shallow(CaCodeSnippet);
11+
});
12+
513
test('is a Vue instance',()=>{
6-
constwrapper=shallow(CaCodeSnippet);
714
expect(wrapper.isVueInstance()).toBeTruthy();
815
});
916

1017
test('Mathes snapshot',()=>{
11-
constwrapper=shallow(CaCodeSnippet);
12-
expect(wrapper.html()).toMatchSnapshot()
18+
expect(wrapper.html()).toMatchSnapshot();
19+
});
20+
21+
describe('when clicked on copy button',()=>{
22+
beforeEach(()=>{
23+
document.createRange=()=>({
24+
selectNode:()=>{},
25+
});
26+
window.getSelection=()=>({
27+
addRange:()=>{},
28+
removeAllRanges:()=>{},
29+
});
30+
});
31+
32+
describe('if copy succeeds',()=>{
33+
beforeEach(()=>{
34+
document.execCommand=jest.fn(()=>true);
35+
wrapper.find('button').trigger('click');
36+
});
37+
38+
it('should call the copy api',()=>{
39+
expect(document.execCommand).toHaveBeenCalledWith('copy');
40+
});
41+
42+
it('should show the feedback',()=>{
43+
expect(wrapper.vm.$data.showFeedback).toBe(true);
44+
});
45+
46+
describe('after 2 seconds',()=>{
47+
beforeEach(()=>{
48+
jest.advanceTimersByTime(2000);
49+
});
50+
51+
it('should hide the feedback',()=>{
52+
expect(wrapper.vm.$data.showFeedback).toBe(false);
53+
});
54+
});
55+
});
1356
});
14-
})
57+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp