Skip to content

Commit efde093

Browse files
committed
update docs
1 parent 9ef1ab9 commit efde093

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,42 @@ INERTIA_SSR_URL = 'http://localhost:13714' # defaults to http://localhost:13714
123123
INERTIA_SSR_ENABLED = False # defaults to False
124124
```
125125

126+
## Testing
127+
128+
Inertia Django ships with a custom TestCase to give you some nice helper methods and assertions.
129+
To use it, just make sure your TestCase inherits from `InertiaTestCase`. `InertiaTestCase` inherits from Django's `django.test.TestCase` so it includes transaction support and a client.
130+
131+
```python
132+
from inertia.test import InertiaTestCase
133+
134+
class ExampleTestCase(InertiaTestCase):
135+
def test_show_assertions(self):
136+
self.client.get('/events/')
137+
138+
# check the component
139+
self.assertComponentUsed('Event/Index')
140+
141+
# access the component name
142+
self.assertEqual(self.component(), 'Event/Index')
143+
144+
# props (including shared props)
145+
self.assertHasExactProps({name: 'Brandon', sport: 'hockey'})
146+
self.assertIncludesProps({sport: 'hockey'})
147+
148+
# access props
149+
self.assertEquals(self.props()['name'], 'Brandon')
150+
151+
# view data
152+
self.assertHasExactViewData({name: 'Brian', sport: 'basketball'})
153+
self.assertIncludesViewData({sport: 'basketball'})
154+
155+
# access view data
156+
self.assertEquals(self.view_data()['name'], 'Brian')
157+
```
158+
159+
The inertia test helper also includes a special `inertia` client that pre-sets the inertia headers
160+
for you to simulate an inertia response. You can access and use it just like the normal client with commands like `self.inertia.get('/events/')`. When using the inertia client, inertia custom assertions **are not** enabled though, so only use it if you want to directly assert against the json response.
161+
126162
## Thank you
127163

128164
A huge thank you to the community members who have worked on InertiaJS for Django before us. Parts of this repo were particularly inspired by [Andres Vargas](https://github.com/zodman) and [Samuel Girardin](https://github.com/girardinsamuel). Additional thanks to Andres for the Pypi project.

0 commit comments

Comments
 (0)