Writing tests for client-side code
The more code you have on the client side, the more it becomes a liability. For server-side code, there’s the well-entrenched unit tests, and for JavaScript, we have QUnit (https://qunitjs.com), which Odoo uses.
Getting ready
We’ll add our tests to the addon developed in the previous recipes, so grab the code from the Making RPC calls to the server recipe and put it in a new module called r4_tests
.
How to do it...
We have to add our test file and make it known to the test mechanism in the appropriate template:
- Add the
static/test/r4_tests.js
file:
odoo.define('r4.tests', function (require) {
- Require what we need:
var test_utils = require('web.test_utils'), FormView = require('web.FormView');
- Provide some test data:
QUnit.module( 'r4', { beforeEach: function() { this.data = { 'res.partner': { fields: { user_id: { ...