File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ exports.tests.add_globals = function()
36
36
a .describe = exports .tests .describe
37
37
-- must prefix with a or stack overflow
38
38
a .it = exports .tests .it
39
+ a .before_each = exports .tests .before_each
40
+ a .after_each = exports .tests .after_each
39
41
end
40
42
41
43
exports .tests .add_to_env = function ()
@@ -50,6 +52,8 @@ exports.tests.add_to_env = function()
50
52
env .a .describe = exports .tests .describe
51
53
-- must prefix with a or stack overflow
52
54
env .a .it = exports .tests .it
55
+ a .before_each = exports .tests .before_each
56
+ a .after_each = exports .tests .after_each
53
57
54
58
setfenv (2 , env )
55
59
end
Original file line number Diff line number Diff line change @@ -10,4 +10,12 @@ M.it = function(s, async_func)
10
10
it (s , util .will_block (async_func ))
11
11
end
12
12
13
+ M .before_each = function (async_func )
14
+ before_each (util .will_block (async_func ))
15
+ end
16
+
17
+ M .after_each = function (async_func )
18
+ after_each (util .will_block (async_func ))
19
+ end
20
+
13
21
return M
Original file line number Diff line number Diff line change
1
+ require (" plenary.async" ).tests .add_to_env ()
2
+
3
+ a .describe (" a.before_each" , function ()
4
+ local counter = 0
5
+
6
+ local set_counter_to_one = a .wrap (function (callback )
7
+ a .util .sleep (5 )
8
+ counter = 1
9
+ end , 1 )
10
+
11
+ a .before_each (a .void (function ()
12
+ set_counter_to_one ()
13
+ end ))
14
+
15
+ a .it (" should run in async context" , function ()
16
+ counter = counter + 1
17
+ assert .are .same (counter , 2 )
18
+ end )
19
+
20
+ a .it (" should run for all tests" , function ()
21
+ counter = counter + 2
22
+ assert .are .same (counter , 3 )
23
+ end )
24
+ end )
25
+
26
+ a .describe (" a.after_each" , function ()
27
+ local counter = 0
28
+
29
+ local set_counter_to_one = a .wrap (function (callback )
30
+ a .util .sleep (5 )
31
+ counter = 1
32
+ end , 1 )
33
+
34
+ a .after_each (a .void (function ()
35
+ set_counter_to_one ()
36
+ end ))
37
+
38
+ a .it (" should not run before first test" , function ()
39
+ counter = counter + 1
40
+ assert .are .same (counter , 1 )
41
+ end )
42
+
43
+ a .it (" should run before the second test" , function ()
44
+ counter = counter + 2
45
+ assert .are .same (counter , 3 )
46
+ end )
47
+
48
+ a .it (" should run before the third test" , function ()
49
+ counter = counter + 3
50
+ assert .are .same (counter , 4 )
51
+ end )
52
+ end )
You can’t perform that action at this time.
0 commit comments