@@ -16,40 +16,58 @@ describe('runAssertion', () => {
1616 it ( 'should assert have.text' , ( ) => {
1717 div . textContent = 'Hello World' ;
1818 expect ( ( ) => runAssertion ( div , 'have.text' , 'Hello World' ) ) . not . toThrow ( ) ;
19- expect ( ( ) => runAssertion ( div , 'have.text' , 'Wrong Text' ) ) . toThrow ( ) ;
19+ const message = runAssertion ( div , 'have.text' , 'Hello World' ) ;
20+ expect ( message ) . toBe ( 'Assertion passed: Text is exactly "Hello World"' ) ;
21+ expect ( ( ) => runAssertion ( div , 'have.text' , 'Wrong Text' ) ) . toThrow ( 'Assertion failed: Expected text to be "Wrong Text", but got "Hello World"' ) ;
22+ } ) ;
23+
24+ it ( 'should assert not.have.text' , ( ) => {
25+ div . textContent = 'Hello World' ;
26+ expect ( ( ) => runAssertion ( div , 'not.have.text' , 'Hello World' ) ) . toThrow ( 'Assertion failed: Expected text to not be "Hello World", but got "Hello World"' ) ;
27+ expect ( ( ) => runAssertion ( div , 'not.have.text' , 'Wrong Text' ) ) . not . toThrow ( ) ;
2028 } ) ;
2129
2230 it ( 'should assert contain.text' , ( ) => {
2331 div . textContent = 'Hello World' ;
2432 expect ( ( ) => runAssertion ( div , 'contain.text' , 'World' ) ) . not . toThrow ( ) ;
25- expect ( ( ) => runAssertion ( div , 'contain.text' , 'Missing' ) ) . toThrow ( ) ;
33+ expect ( ( ) => runAssertion ( div , 'contain.text' , 'Missing' ) ) . toThrow ( 'Assertion failed: Expected text to contain "Missing", but got "Hello World"' ) ;
34+ const message = runAssertion ( div , 'contain.text' , 'World' ) ;
35+ expect ( message ) . toBe ( 'Assertion passed: Text contains "World"' ) ;
2636 } ) ;
2737
2838 it ( 'should assert be.empty' , ( ) => {
2939 div . textContent = '' ;
3040 expect ( ( ) => runAssertion ( div , 'be.empty' ) ) . not . toThrow ( ) ;
41+ const message = runAssertion ( div , 'be.empty' ) ;
42+ expect ( message ) . toBe ( 'Assertion passed: Text is empty' ) ;
3143 div . textContent = 'Not Empty' ;
32- expect ( ( ) => runAssertion ( div , 'be.empty' ) ) . toThrow ( ) ;
44+ expect ( ( ) => runAssertion ( div , 'be.empty' ) ) . toThrow ( 'Assertion failed: Expected text to be empty, but got "Not Empty"' ) ;
3345 } ) ;
3446
3547 // Attribute assertions
3648 it ( 'should assert have.attr' , ( ) => {
3749 div . setAttribute ( 'data-test' , 'value' ) ;
3850 expect ( ( ) => runAssertion ( div , 'have.attr' , 'data-test' , 'value' ) ) . not . toThrow ( ) ;
39- expect ( ( ) => runAssertion ( div , 'have.attr' , 'data-test' , 'wrong' ) ) . toThrow ( ) ;
51+ expect ( ( ) => runAssertion ( div , 'have.attr' , 'data-test' , 'wrong' ) ) . toThrow ( 'Assertion failed: Expected attribute "data-test" to be "wrong", but got "value"' ) ;
52+ const message = runAssertion ( div , 'have.attr' , 'data-test' , 'value' ) ;
53+ expect ( message ) . toBe ( 'Assertion passed: Attribute "data-test" is "value"' ) ;
4054 } ) ;
4155
4256 it ( 'should assert have.value' , ( ) => {
4357 input . value = 'input value' ;
4458 expect ( ( ) => runAssertion ( input , 'have.value' , 'input value' ) ) . not . toThrow ( ) ;
45- expect ( ( ) => runAssertion ( input , 'have.value' , 'wrong value' ) ) . toThrow ( ) ;
59+ expect ( ( ) => runAssertion ( input , 'have.value' , 'wrong value' ) ) . toThrow ( 'Assertion failed: Expected value to be "wrong value", but got "input value"' ) ;
60+ const message = runAssertion ( input , 'have.value' , 'input value' ) ;
61+ expect ( message ) . toBe ( 'Assertion passed: Value is "input value"' ) ;
4662 } ) ;
4763
4864 // State assertions
4965 it ( 'should assert be.disabled and be.enabled' , ( ) => {
5066 input . disabled = true ;
5167 expect ( ( ) => runAssertion ( input , 'be.disabled' ) ) . not . toThrow ( ) ;
52- expect ( ( ) => runAssertion ( input , 'be.enabled' ) ) . toThrow ( ) ;
68+ expect ( ( ) => runAssertion ( input , 'be.enabled' ) ) . toThrow ( 'Assertion failed: Expected element to be enabled' ) ;
69+ const message = runAssertion ( input , 'be.disabled' ) ;
70+ expect ( message ) . toBe ( 'Assertion passed: Element is disabled' ) ;
5371 input . disabled = false ;
5472 expect ( ( ) => runAssertion ( input , 'be.enabled' ) ) . not . toThrow ( ) ;
5573 expect ( ( ) => runAssertion ( input , 'be.disabled' ) ) . toThrow ( ) ;
@@ -59,44 +77,54 @@ describe('runAssertion', () => {
5977 input . type = 'checkbox' ;
6078 input . checked = true ;
6179 expect ( ( ) => runAssertion ( input , 'be.checked' ) ) . not . toThrow ( ) ;
80+ const message = runAssertion ( input , 'be.checked' ) ;
81+ expect ( message ) . toBe ( 'Assertion passed: Element is checked' ) ;
6282 input . checked = false ;
63- expect ( ( ) => runAssertion ( input , 'be.checked' ) ) . toThrow ( ) ;
83+ expect ( ( ) => runAssertion ( input , 'be.checked' ) ) . toThrow ( 'Assertion failed: Expected element to be checked' ) ;
6484 } ) ;
6585
6686 it ( 'should assert be.selected' , ( ) => {
6787 option . selected = true ;
6888 expect ( ( ) => runAssertion ( option , 'be.selected' ) ) . not . toThrow ( ) ;
89+ const message = runAssertion ( option , 'be.selected' ) ;
90+ expect ( message ) . toBe ( 'Assertion passed: Element is selected' ) ;
6991 option . selected = false ;
70- expect ( ( ) => runAssertion ( option , 'be.selected' ) ) . toThrow ( ) ;
92+ expect ( ( ) => runAssertion ( option , 'be.selected' ) ) . toThrow ( 'Assertion failed: Expected element to be selected' ) ;
7193 } ) ;
7294
7395 it ( 'should assert be.focused' , ( ) => {
7496 document . body . appendChild ( input ) ;
7597 input . focus ( ) ;
7698 expect ( ( ) => runAssertion ( input , 'be.focused' ) ) . not . toThrow ( ) ;
99+ const message = runAssertion ( input , 'be.focused' ) ;
100+ expect ( message ) . toBe ( 'Assertion passed: Element is focused' ) ;
77101 const anotherInput = document . createElement ( 'input' ) ;
78102 document . body . appendChild ( anotherInput ) ;
79103 anotherInput . focus ( ) ;
80- expect ( ( ) => runAssertion ( input , 'be.focused' ) ) . toThrow ( ) ;
104+ expect ( ( ) => runAssertion ( input , 'be.focused' ) ) . toThrow ( 'Assertion failed: Expected element to be focused' ) ;
81105 } ) ;
82106
83107 // Visibility assertions
84108 it ( 'should assert be.visible and not.be.visible' , ( ) => {
85109 div . style . display = 'block' ;
86110 document . body . appendChild ( div ) ;
87111 expect ( ( ) => runAssertion ( div , 'be.visible' ) ) . not . toThrow ( ) ;
112+ const message = runAssertion ( div , 'be.visible' ) ;
113+ expect ( message ) . toBe ( 'Assertion passed: Element is visible' ) ;
88114 div . style . display = 'none' ;
89- expect ( ( ) => runAssertion ( div , 'be.visible' ) ) . toThrow ( ) ;
115+ expect ( ( ) => runAssertion ( div , 'be.visible' ) ) . toThrow ( 'Assertion failed: Expected element to be visible' ) ;
90116 expect ( ( ) => runAssertion ( div , 'not.be.visible' ) ) . not . toThrow ( ) ;
91117 } ) ;
92118
93119 // Class assertions
94120 it ( 'should assert have.class and not.have.class' , ( ) => {
95121 div . className = 'active' ;
96122 expect ( ( ) => runAssertion ( div , 'have.class' , 'active' ) ) . not . toThrow ( ) ;
97- expect ( ( ) => runAssertion ( div , 'have.class' , 'inactive' ) ) . toThrow ( ) ;
123+ const message = runAssertion ( div , 'have.class' , 'active' ) ;
124+ expect ( message ) . toBe ( 'Assertion passed: Element has class "active"' ) ;
125+ expect ( ( ) => runAssertion ( div , 'have.class' , 'inactive' ) ) . toThrow ( 'Assertion failed: Expected element to have class "inactive"' ) ;
98126 expect ( ( ) => runAssertion ( div , 'not.have.class' , 'inactive' ) ) . not . toThrow ( ) ;
99- expect ( ( ) => runAssertion ( div , 'not.have.class' , 'active' ) ) . toThrow ( ) ;
127+ expect ( ( ) => runAssertion ( div , 'not.have.class' , 'active' ) ) . toThrow ( 'Assertion failed: Expected element to not have class "active"' ) ;
100128 } ) ;
101129
102130 // default case
0 commit comments