forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
46 lines (43 loc) · 1.08 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Seeding Your Database with Test Data</title>
</head>
<body>
<h1>Seeding Your Database with Test Data</h1>
<p>
This example has the client app.js make an XHR for the data from the server.
</p>
<p>
In this recipe we are going to seed the database with Cypress so we can control the initial data payload.
</p>
<div id="posts"></div>
<script src="/node_modules/jquery/dist/jquery.js"></script>
<script>
const App = {
start: function(){
$.getJSON('/posts.json')
.done((posts) => {
this.displayPosts(posts)
})
},
displayPosts: function(posts = []){
if (posts.length) {
const postsDom = posts.map((post) => (
`<li>
<h2>${post.title}</h2>
<p>${post.date}</p>
<p>${post.body}</p>
</li>`
)).join('')
$('#posts').append(`<ul>${postsDom}</ul>`)
} else {
$('#posts').text('No posts')
}
}
}
App.start()
</script>
</body>
</html>