- Set up Jasmine Development Environment
- Set the Jasmine Config Property
- Create Javascript Files including Jasmine.json, JS Modules & Unit tests
Setup Jasmine Development Environment
I would suggest setting up a Docker image for Javascript environment consisting of key tools such as grunt, jscs, jshint, typescript, browserify, nodejs etc. Check my page on How to setup Javascript Dev Environment using Dockers.
Set the Jasmine Config Property
Set the Jasmine config property (environment variable) pointing to folder where jasmine.json file can be found. As I am executing jasmine from topmost folder (/home/ashukla/js) under which jasmine.json is found, I set the path by executing “export JASMINE_CONFIG_PATH=/home/ashukla/js/jasmine.json”.
Create Javascript Files including Jasmine.json, JS Modules & Unit tests
Make a directory under with following subfolders and a configuration file will be placed:
- jasmine.json: This is a configuration file which defines the path where unit tests saved in ***Spec.js file will be found. Following is how the default jasmine.json file looks like:
{ "spec_dir": "spec", "spec_files": [ "**/*[sS]pec.js" ], "helpers": [ "helpers/**/*.js" ], "stopSpecOnExpectationFailure": false, "random": false }
- lib: This folder will consist of JS files to be tested. In this example, I have created a class/module named as Person.js. Following is the sample code:
function Person(){ this.age = 0; this.isAdult = false; }; Person.prototype.setAge = function(age) { this.age = age; if(this.age > 17) { this.isAdult = true; } else { this.isAdult = false; } }; module.exports = Person;
- spec: This folder will consist of unit tests files. I have created a unit test file such as PersonSpec.js which consists of unit tests to test the Person.js module. Following is the code sample:
describe("Person", function() { var Person = require('../lib/Person'); var person; beforeEach(function() { person = new Person(); }); it("is not an adult", function() { expect(person.isAdult).toBe(false); person.setAge(16); expect(person.isAdult).toBe(false); }); it("is an adult", function() { person.setAge(18); expect(person.isAdult).toBe(true); }); });
- Agentic Reasoning Design Patterns in AI: Examples - October 18, 2024
- LLMs for Adaptive Learning & Personalized Education - October 8, 2024
- Sparse Mixture of Experts (MoE) Models: Examples - October 6, 2024
I found it very helpful. However the differences are not too understandable for me