Hi Guys,
I am pretty new to meteor. I was trying to use autoform to create an automatic form and test it. But I can’t seem to get it right.
I was simply trying to test an error scenario for the book example. Where we have a book schema with required fields and submitting the empty form to give us the error messages.
I am using both packages collection2 and autoform, my schema looks like this:
Books = new Mongo.Collection("books");
var Schemas = {};
Schemas.Book = new SimpleSchema({
title: {
type: String,
label: "Title",
max: 200
},
author: {
type: String,
label: "Author"
},
copies: {
type: Number,
label: "Number of copies",
min: 0
},
lastCheckedOut: {
type: Date,
label: "Last date this book was checked out",
optional: true
},
summary: {
type: String,
label: "Brief summary",
optional: true,
max: 1000
}
});
Books.attachSchema(Schemas.Book);
I added a form like this:
<head>
<title>test_autoform_submit</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> insertBookForm}}
</body>
<template name="insertBookForm">
{{> quickForm collection="Books" id="insertBookForm" type="insert"}}
</template>
I added velocity and jasmine and my test looks like this:
describe("Initial insert form ", function() {
it("insert form should submit", function() {
var spyEvent = spyOnEvent('#insertBookForm', 'submit');
var form = $('#insertBookForm');
form.submit();
expect(spyEvent).toHaveBeenTriggered();
var block = form.find("span.help-block")
expect(block[0].outerHTML).toContain('Title is required');
});
});
And my error is:
Expected '<span class="help-block"></span>' to contain 'Title is required'.
Showing that no error appeared for the title.
Can somebody help and explain to me why is this happening?
I have an example repository here that you can download: https://github.com/andreorvalho/test_autoform_submit
I am not sure if this has to do with some async situation I am not understanding or if it is autoform that does things a little different.
Hope somebody can help me.
Best regards,
Andre