### Install Jasmine Examples Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/ruby.md Install sample Jasmine specs and their implementations to get started quickly. This can be done via Rails generators or the command-line tool. ```sh rails g jasmine:examples ``` ```sh jasmine examples ``` -------------------------------- ### start() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_browser-runner-api/4.0/Server.html Starts the server. Returns a promise that resolves upon successful start. ```APIDOC ## start() ### Description Starts the server. ### Returns - **Promise.** - A promise that resolves upon successful start. ``` -------------------------------- ### install() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/Clock.html Installs the mock clock, replacing the built-in methods with mock implementations. ```APIDOC ## install() ### Description Install the mock clock over the built-in methods. Since: * 2.0.0 ### Method GET ### Endpoint /install ### Returns Type [Clock](Clock.html) ``` -------------------------------- ### Install, Build, and Test Dependencies Source: https://github.com/jasmine/jasmine.github.io/blob/master/examples/module-mocking/node-typescript-cjs/README.md Standard commands to set up and run the project. Ensure Node.js and npm are installed. ```shell npm install npm run build npm test ``` -------------------------------- ### Browser Setup with jasmine-browser-runner CLI Source: https://context7.com/jasmine/jasmine.github.io/llms.txt Install and initialize jasmine-browser-runner for running Jasmine specs in real browsers or headless Chrome. Use 'serve' for development and 'runSpecs' for CI. ```sh npm install --save-dev jasmine-browser-runner jasmine-core npx jasmine-browser-runner init npx jasmine-browser-runner serve # interactive dev server at localhost:8888 npx jasmine-browser-runner runSpecs # CI headless run ``` -------------------------------- ### Generate Example Files Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/nodejs.md Generate example spec and source files to help you get started with writing your first Jasmine tests. ```sh npx jasmine examples ``` -------------------------------- ### Install Dependencies Source: https://github.com/jasmine/jasmine.github.io/blob/master/examples/module-mocking/node-cjs-testdouble/README.md Install the necessary packages for testing. This includes the testing framework and the mocking library. ```shell npm install npm test ``` -------------------------------- ### start() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.2/Timer.html Starts the timer, marking the beginning of the time measurement. ```APIDOC ## start() ### Description Starts the timer. ``` -------------------------------- ### Install React Testing Library (Yarn) Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_node.md Install the `@testing-library/react` package as a development dependency using Yarn. ```shell $ yarn add --dev @testing-library/react ``` -------------------------------- ### startServer Source: https://github.com/jasmine/jasmine.github.io/blob/master/_browser-runner-api/4.0/module-jasmine-browser-runner.html Starts a Server instance to serve specs and supporting files via HTTP. Returns a Promise that resolves when the server is successfully started. ```APIDOC ## startServer(options) ### Description Starts a [`Server`](Server.html) that will serve the specs and supporting files via HTTP. ### Method (static) ### Parameters #### Parameters - **options** (ServerCtorOptions) - Description: Options to use to construct the server. ### Returns A promise that is resolved when the server is started. Type: Promise. ``` -------------------------------- ### Install React Testing Library (NPM) Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_node.md Install the `@testing-library/react` package as a development dependency using NPM. ```shell $ npm install --save-dev @testing-library/react ``` -------------------------------- ### Install and Initialize Jasmine (Node.js) Source: https://context7.com/jasmine/jasmine.github.io/llms.txt Install Jasmine locally using npm and initialize the project structure. Run specs using the `npx jasmine` command. ```sh npm install --save-dev jasmine npx jasmine init # creates spec/support/jasmine.json npx jasmine examples # generates example spec and source files npx jasmine # runs all specs ``` -------------------------------- ### Refactored Nested `describe` Setup in Jasmine Source: https://github.com/jasmine/jasmine.github.io/blob/master/_faq/testing/let.md This refactored example shows how to correctly handle nested `describe` blocks by inlining setup logic or using helper functions, avoiding the need for a `let` equivalent. ```javascript describe('When the user is logged in', function() { it('does some things that apply to any user', function() { logIn(MyFixtures.anyUser); // ... }); describe('as an admin', function() { beforeEach(function() { logIn(MyFixtures.adminUser); }); it('shows the admin controls', function() { // ... }); }); describe('as a non-admin', function() { beforeEach(function() { logIn(MyFixtures.nonAdminUser); }); it('does not show the admin controls', function() { // ... }); }); function logIn(user) { // Do something, potentially complicated, that causes the system to run // with `user` logged in. } }); ``` -------------------------------- ### Setup and Teardown with beforeAll and afterAll Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/your_first_suite.md Use beforeAll to run code once before all specs in a describe block and afterAll to run code once after all specs have finished. This is useful for expensive setup or teardown operations. ```javascript describe("A suite with some shared setup", function() { let foo = 0; beforeAll(function() { foo = 1; }); afterAll(function() { foo = 0; }); it("does something with foo set to 1", function() { expect(foo).toEqual(1); }); }); ``` -------------------------------- ### Install React Testing Library (npm) Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_browser.md Install the React Testing Library package as a development dependency using npm. ```shell npm install --save-dev @testing-library/react ``` -------------------------------- ### RemoteSeleniumGridConfig Example Source: https://github.com/jasmine/jasmine.github.io/blob/master/_browser-runner-api/4.0/RemoteSeleniumGridConfig.html An example configuration object for RemoteSeleniumGridConfig, demonstrating the 'url' property and how to include browser-specific options like 'bstack:options'. ```APIDOC ## RemoteSeleniumGridConfig Configuration for running specs on a remote Selenium grid. Any additional properties, such as "sauce:options" or "bstack:options", will be included in the capabilities object passed through to Selenium Webdriver. ### Example ```json { "url": "https://hub-cloud.browserstack.com/wd/hub", "bstack:options": { "browserVersion": "16", "os": "OS X", "osVersion": "Monterey", "local": "true", "localIdentifier": "tunnel ID", "debug": "true", "userName": "your BrowserStack username", "accessKey": "your BrowserStack access key" } } ``` ### Members #### url :string URL of the remote Selenium grid ##### Type: * string ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/jasmine/jasmine.github.io/blob/master/README.md Starts a local server to preview documentation changes. Access the preview through your web browser. ```bash bundle exec rake serve ``` -------------------------------- ### Install Ruby Dependencies Source: https://github.com/jasmine/jasmine.github.io/blob/master/README.md Installs Ruby dependencies for the project. Use `--path vendor/bundle` to install them locally instead of globally. ```bash bundle install --path vendor/bundle ``` -------------------------------- ### Timer.start() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/Timer.html Starts the timer. ```APIDOC ## start() ### Description Starts the timer. ### Method `start()` ``` -------------------------------- ### beforeAll Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/global.html Runs setup code once before all specs in a describe block. Useful for initializing resources that will be used by multiple tests. Be cautious of state leakage. ```APIDOC ## beforeAll(functionopt, timeoutopt) ### Description Run some shared setup once before all of the specs in the [`describe`](global.html#describe) are run. _Note:_ Be careful, sharing the setup from a beforeAll makes it easy to accidentally leak state between your specs so that they erroneously pass or fail. `beforeAll` may be overwritten by user or library code to customize Jasmine's behavior. ### Parameters #### Parameters - **function** ([implementationCallback](global.html#implementationCallback)) - Optional - Function that contains the code to setup your specs. - **timeout** (Int) - Optional - Custom timeout for an async beforeAll. Defaults to [`jasmine.DEFAULT_TIMEOUT_INTERVAL`](jasmine.html#.DEFAULT_TIMEOUT_INTERVAL). ### Since * 2.1.0 ### See * [async](/tutorials/async) ``` -------------------------------- ### Install Jasmine Mock Clock Source: https://github.com/jasmine/jasmine.github.io/blob/master/_upgrade-guides/2.0.html The Jasmine mock clock is now an instantiated object and must be explicitly installed using `jasmine.clock().install()`. Previously, `jasmine.Clock.useMock()` was used. ```javascript jasmine.clock().install(); ``` -------------------------------- ### Install jasmine-browser-runner with npm Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/browser.md Installs the necessary packages for jasmine-browser-runner using npm. This is the first step to setting up Jasmine for browser testing. ```bash npm install --save-dev jasmine-browser-runner jasmine-core npx jasmine-browser-runner init ``` -------------------------------- ### Install ignore-styles Package with NPM Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_node.md Install the 'ignore-styles' package using NPM to handle CSS and image imports during testing. ```shell $ npm install --save-dev ignore-styles ``` -------------------------------- ### Start jasmine-browser-runner server Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/browser.md Starts the development server for jasmine-browser-runner, allowing interactive testing in a browser. Access tests at http://localhost:8888/. ```bash npx jasmine-browser-runner serve ``` -------------------------------- ### Install ignore-styles Package with Yarn Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_node.md Install the 'ignore-styles' package using Yarn to handle CSS and image imports during testing. ```shell $ yarn add --dev ignore-styles ``` -------------------------------- ### Basic Spy Setup and Checks Source: https://github.com/jasmine/jasmine.github.io/blob/master/_upgrade-guides/2.0.html The fundamental way to set up a spy and perform basictoHaveBeenCalledWith checks remains consistent. ```javascript spy('foo'); spy('bar'); expect(spy).toHaveBeenCalledWith('foo'); ``` -------------------------------- ### Install Jasmine Clock Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/your_first_suite.md Install the Jasmine Clock to enable testing of time-dependent code. This should be done in a `beforeEach` block. ```javascript let timerCallback; beforeEach(function () { timerCallback = jasmine.createSpy("timerCallback"); jasmine.clock().install(); }); ``` -------------------------------- ### Simple Jasmine Library Example (CommonJS) Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/nodejs.md A basic example demonstrating how to use Jasmine as a library in a Node.js project using CommonJS modules. It loads configuration, sets reporter options, and executes tests. ```javascript // CommonJS const Jasmine = require('jasmine'); const runner = new Jasmine(); runner.loadConfigFile('spec/support/jasmine.json') .then(function() { runner.configureDefaultReporter({ showColors: false }); runner.execute(); }); ``` -------------------------------- ### Install Development Dependencies with NPM Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_node.md Install necessary development packages for testing React apps with Jasmine using NPM. ```shell $ npm install --save-dev @babel/core \ @babel/register \ babel-preset-react-app \ cross-env \ jsdom \ jasmine ``` -------------------------------- ### Jasmine Setup and Teardown Hooks Source: https://context7.com/jasmine/jasmine.github.io/llms.txt Use lifecycle hooks like `beforeAll`, `afterAll`, `beforeEach`, and `afterEach` to manage setup and teardown for suites and specs. Hooks share scope via closures or `this`. ```javascript describe("A suite with shared state", function() { let db; let connection; beforeAll(function() { db = openDatabase(); // runs once before all specs }); afterAll(function() { db.close(); // runs once after all specs }); beforeEach(function() { connection = db.connect(); // fresh connection for each spec }); afterEach(function() { connection.close(); // clean up after each spec }); it("can read records", function() { expect(connection.read("users")).toBeDefined(); }); it("can write records", function() { connection.write("users", { name: "Alice" }); expect(connection.count("users")).toBeGreaterThan(0); }); }); ``` -------------------------------- ### Install jasmine-browser-runner with yarn Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/browser.md Installs the necessary packages for jasmine-browser-runner using yarn. This is an alternative to npm for setting up Jasmine for browser testing. ```bash yarn add -D jasmine-browser-runner jasmine-core npx jasmine-browser-runner init ``` -------------------------------- ### Start Jasmine Browser Server Programmatically (CommonJS) Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/browser.md Programmatically start the Jasmine browser server using CommonJS modules, dynamically importing the configuration. ```javascript // CommonJS const path = require('path'); const jasmineBrowser = require('jasmine-browser-runner'); import('./spec/support/jasmine-browser.mjs') .then(function({default: config}) { config.projectBaseDir = path.resolve('some/path'); jasmineBrowser.startServer(config, { port: 4321 }); }); ``` -------------------------------- ### Install Development Dependencies with Yarn Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_node.md Install necessary development packages for testing React apps with Jasmine using Yarn. ```shell $ yarn add --dev @babel/core \ @babel/register \ babel-preset-react-app \ cross-env \ jsdom \ jasmine ``` -------------------------------- ### Start Jasmine Browser Server Programmatically (ESM) Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/browser.md Programmatically start the Jasmine browser server using ESM imports, configuring the project base directory and port. ```javascript // ESM import path from 'path'; import jasmineBrowser from 'jasmine-browser-runner'; import config from './spec/support/jasmine-browser.mjs'; config.projectBaseDir = path.resolve('some/path'); jasmineBrowser.startServer(config, { port: 4321 }); ``` -------------------------------- ### Setup Ahead-of-Time Responses Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/mocking_ajax.md Set up responses for specific URLs in advance. These responses will be returned immediately when the corresponding AJAX request is made. ```javascript it("allows responses to be setup ahead of time", function () { const doneFn = jasmine.createSpy("success"); ``` -------------------------------- ### Configure Global Setup and Teardown in Jasmine Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/running_specs_in_parallel.md Use the `globalSetup` and `globalTeardown` functions in your Jasmine configuration file for exactly-once global setup and teardown, especially useful for out-of-process state management in parallel execution. If these functions are `async` or return a promise, Jasmine will wait for them to resolve. ```javascript module.exports = { spec_dir: "spec", // ... globalSetup() { // ... your setup code here }, globalTeardown() { // ... your teardown code here } } ``` -------------------------------- ### Install jasmine-ajax Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/mocking_ajax.md Install the jasmine-ajax plugin in a beforeEach block to mock all AJAX calls across an entire test suite. This stubs out the global XMLHttpRequest. ```javascript beforeEach(function() { jasmine.Ajax.install(); }); ``` -------------------------------- ### Simple Jasmine Library Example (ESM) Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/nodejs.md An example of using Jasmine as a library with ECMAScript Modules (ESM). It shows loading configuration, configuring the reporter, and executing tests asynchronously. ```javascript // or ESM: import Jasmine from 'jasmine'; const runner = new Jasmine(); await runner.loadConfigFile('spec/support/jasmine.json'); runner.configureDefaultReporter({ showColors: false }); runner.execute(); ``` -------------------------------- ### Start Jasmine Development Server Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/ruby.md Run the `rake jasmine` task to start a persistent server. This allows you to open a browser and run your Jasmine tests interactively. ```sh rake jasmine ``` -------------------------------- ### installGlobalErrors Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/ParallelReportDispatcher.html Installs a global error handler. Once installed, any unhandled exceptions or unhandled promise rejections in the environment will be caught and passed to the onError callback provided during instantiation. ```APIDOC ## installGlobalErrors() ### Description Installs a global error handler. After this method is called, any unhandled exceptions or unhandled promise rejections will be passed to the onError callback that was passed to the constructor. ``` -------------------------------- ### Install Jasmine for Browsers Source: https://github.com/jasmine/jasmine.github.io/blob/master/pages/getting_started.html Add the necessary packages for running Jasmine tests in a browser environment. ```bash npm install --save-dev jasmine-browser-runner jasmine-core ``` -------------------------------- ### Async Matcher Usage Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.2/async-matchers.html Examples demonstrating the correct usage of async matchers with `expectAsync`. It's crucial to `await` the result or `return` the promise chain. ```APIDOC ## Async Matcher Usage Examples ### Description Examples demonstrating the correct usage of async matchers with `expectAsync`. It's crucial to `await` the result or `return` the promise chain. ### Code Examples ```javascript // Good await expectAsync(aPromise).toBeResolved(); // Good return expectAsync(aPromise).toBeResolved(); // Good return expectAsync(aPromise).toBeResolved() .then(function() { // more spec code }); // Bad expectAsync(aPromise).toBeResolved(); ``` ``` -------------------------------- ### jasmineStarted Method Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.2/HtmlReporterV2.html Callback invoked after all specs are loaded but before execution begins. Useful for setup operations. ```APIDOC ## jasmineStarted(suiteInfo, doneopt) ### Description `jasmineStarted` is called after all of the specs have been loaded, but just before execution starts. ### Method jasmineStarted ### Parameters: Name | Type | Attributes | Description ---|---|---|--- `suiteInfo` | [JasmineStartedInfo](global.html#JasmineStartedInfo) | | Information about the full Jasmine suite that is being run `done` | function | | Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on. Implements: * [Reporter#jasmineStarted](Reporter.html#jasmineStarted) See: * [async](/tutorials/async) ### Returns: Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion. ``` -------------------------------- ### port() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_browser-runner-api/4.0/Server.html Gets the port that the server is listening on. The server must be started before this method is called. ```APIDOC ## port() ### Description Gets the port that the server is listening on. The server must be started before this method is called. ### Returns - **number** - The port number ``` -------------------------------- ### hostname() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_browser-runner-api/4.0/Server.html Gets the hostname that the server is listening on. The server must be started before this method is called. ```APIDOC ## hostname() ### Description Gets the hostname that the server is listening on. The server must be started before this method is called. ### Returns - **string** - The hostname (localhost if not specified) ``` -------------------------------- ### Install Jasmine Browser Runner with npm Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_browser.md Use this command to add jasmine-core and jasmine-browser-runner as development dependencies when using npm. ```shell $ npm install --save-dev jasmine-core jasmine-browser-runner ``` -------------------------------- ### scheme() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_browser-runner-api/4.0/Server.html Gets the URL scheme that the server is listening on. The server must be started before this method is called. ```APIDOC ## scheme() ### Description Gets the URL scheme that the server is listening on. The server must be started before this method is called. ### Returns - **string** - The URL scheme ('http' or 'https') ``` -------------------------------- ### Install Jasmine Browser Runner with Yarn Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_browser.md Use this command to add jasmine-core and jasmine-browser-runner as development dependencies when using Yarn. ```shell $ yarn add --dev jasmine-core jasmine-browser-runner ``` -------------------------------- ### Instantiate and Use Timer Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/Timer.html Instantiate a new Timer object, start it, and then get the elapsed time. The elapsed time is returned in milliseconds. ```javascript const timer = new jasmine.Timer(); timer.start(); const elapsed = timer.elapsed() ``` -------------------------------- ### suiteStarted(result, doneopt) Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/HtmlReporterV2.html `suiteStarted` is invoked when a `describe` starts to run. It provides information about the individual `describe` block being executed. ```APIDOC ## suiteStarted(result, doneopt) ### Description Invoked when a `describe` block begins execution. Provides details about the specific `describe` being run. ### Parameters #### Parameters - **result** ([SuiteStartedEvent](global.html#SuiteStartedEvent)) - Information about the individual [`describe`](global.html#describe) being run. - **doneopt** (function) - Optional. Used to specify asynchronous callback, signaling Jasmine to wait until it's called. ### Returns Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion. ``` -------------------------------- ### Incorrect Nested `describe` Setup in Jasmine Source: https://github.com/jasmine/jasmine.github.io/blob/master/_faq/testing/let.md This example demonstrates a common but incorrect pattern for setting up tests with nested `describe` blocks in Jasmine, where inner `beforeEach` calls do not execute before outer ones. ```javascript describe('When the user is logged in', function() { let user = MyFixtures.anyUser beforeEach(function() { // Do something, potentially complicated, that causes the system to run // with `user` logged in. }); it('does some things that apply to any user', function() { // ... }); describe('as an admin', function() { beforeEach(function() { user = MyFixtures.adminUser; }); it('shows the admin controls', function() { // ... }); }); describe('as a non-admin', function() { beforeEach(function() { user = MyFixtures.nonAdminUser; }); it('does not show the admin controls', function() { // ... }); }); }); ``` -------------------------------- ### Initialize Jasmine for Node.js Source: https://github.com/jasmine/jasmine.github.io/blob/master/pages/getting_started.html Set up the default Jasmine configuration file in your project. ```bash npx jasmine init ``` -------------------------------- ### Setup and Teardown with beforeEach and afterEach Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/your_first_suite.md Use beforeEach to run code before each spec and afterEach to run code after each spec. This is useful for resetting state or performing cleanup. ```javascript describe("A suite with some shared setup", function() { let foo = 0; beforeEach(function() { foo += 1; }); afterEach(function() { foo = 0; }); it("does something", function() { expect(foo).toEqual(1); }); }); ``` -------------------------------- ### Server Constructor Source: https://github.com/jasmine/jasmine.github.io/blob/master/_browser-runner-api/4.0/Server.html Initializes a new instance of the Server class. Options can be provided to configure the server. ```APIDOC ## Server(options) ### Description Initializes a new instance of the Server class. ### Parameters #### Parameters - **options** (ServerCtorOptions) - Description of the options parameter ``` -------------------------------- ### Install Jasmine with Pip Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/python.md Install the Jasmine Python package using pip. This command can also be added to your requirements.txt file. ```sh pip install jasmine ``` -------------------------------- ### beforeEach Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/global.html Runs setup code before each individual spec within a describe block. Essential for ensuring a clean state for every test, promoting test independence. ```APIDOC ## beforeEach(functionopt, timeoutopt) ### Description Run some shared setup before each of the specs in the [`describe`](global.html#describe) in which it is called. `beforeEach` may be overwritten by user or library code to customize Jasmine's behavior. ### Parameters #### Parameters - **function** ([implementationCallback](global.html#implementationCallback)) - Optional - Function that contains the code to setup your specs. - **timeout** (Int) - Optional - Custom timeout for an async beforeEach. Defaults to [`jasmine.DEFAULT_TIMEOUT_INTERVAL`](jasmine.html#.DEFAULT_TIMEOUT_INTERVAL). ### Since * 1.3.0 ### See * [async](/tutorials/async) ``` -------------------------------- ### Initialize Jasmine with NPM Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_node.md Initialize Jasmine for your project using NPM. ```shell $ npx jasmine init ``` -------------------------------- ### boot(reinitializeopt) Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.2/module-jasmine-core.html Boots a copy of Jasmine and returns an object as described in the jasmine namespace. It can optionally reinitialize Jasmine if a copy already exists. ```APIDOC ## boot(reinitializeopt) ### Description Boots a copy of Jasmine and returns an object as described in [`jasmine`](jasmine.html). ### Method (static) ### Parameters #### Parameters - **reinitialize** (boolean) - Optional - true - Whether to create a new copy of Jasmine if one already exists ### Returns Type [jasmine](jasmine.html) ``` -------------------------------- ### uninstallGlobalErrors Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/ParallelReportDispatcher.html Uninstalls the global error handler that was previously installed by installGlobalErrors(). This reverts the error handling behavior to its state before installation. ```APIDOC ## uninstallGlobalErrors() ### Description Uninstalls the global error handler. ``` -------------------------------- ### Booting Jasmine Core Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/module-jasmine-core.html Initializes a copy of the Jasmine testing framework. Optionally, it can reinitialize if a copy already exists. Returns the Jasmine object. ```javascript const jasmine = require('jasmine-core').boot(); ``` -------------------------------- ### Start Jasmine Server Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/python.md Start the Jasmine server to serve your project's Jasmine suite in a browser. The default port is 8888. ```sh jasmine server ``` -------------------------------- ### Initialize a Jasmine Project Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/python.md Initialize a new project for Jasmine. This command creates a spec directory and a configuration YAML file. ```sh jasmine init ``` -------------------------------- ### Initialize Jasmine for Browser Runner Source: https://github.com/jasmine/jasmine.github.io/blob/master/pages/getting_started.html Set up the Jasmine browser runner configuration in your project. ```bash npx jasmine-browser-runner init ``` -------------------------------- ### Run All Specs Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/nodejs.md Execute all configured Jasmine specs by running `jasmine` or `npx jasmine` from the project root. ```sh npx jasmine ``` -------------------------------- ### Install Jasmine with Rails Generator Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/ruby.md Use the Rails generator to install Jasmine, which sets up default configuration files like jasmine.yml and jasmine_helper.rb. ```sh rails g jasmine:install ``` -------------------------------- ### Remote Selenium Grid Configuration Example Source: https://github.com/jasmine/jasmine.github.io/blob/master/_browser-runner-api/4.0/RemoteSeleniumGridConfig.html Configure connection details and browser-specific options for a remote Selenium grid. Any properties under 'bstack:options' (or similar vendor prefixes) are passed directly to the Selenium WebDriver capabilities. ```json { "url": "https://hub-cloud.browserstack.com/wd/hub", "bstack:options": { "browserVersion": "16", "os": "OS X", "osVersion": "Monterey", "local": "true", "localIdentifier": "tunnel ID", "debug": "true", "userName": "your BrowserStack username", "accessKey": "your BrowserStack access key" } } ``` -------------------------------- ### Install Jasmine Globally Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/nodejs.md Optionally install Jasmine globally for command-line access without npx. This is generally not recommended to avoid versioning conflicts. ```sh npm install -g jasmine ``` -------------------------------- ### boot Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/module-jasmine-core.html Boots a copy of Jasmine and returns an object containing the Jasmine interface. It can optionally reinitialize Jasmine if a copy already exists. ```APIDOC ## boot(reinitialize) ### Description Boots a copy of Jasmine and returns an object as described in [`jasmine`](jasmine.html). ### Method (static) ### Parameters #### Parameters - **reinitialize** (boolean) - Optional - Whether to create a new copy of Jasmine if one already exists. Defaults to true. ### Returns - **jasmine** ([`jasmine`](jasmine.html)) - An object representing the Jasmine interface. ``` -------------------------------- ### Timer Constructor and Usage Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/Timer.html Demonstrates how to instantiate and use the Timer class to measure time. ```APIDOC ## Timer() ### Description Tracks elapsed time. ### Constructor #### new Timer() ##### Example ```javascript const timer = new jasmine.Timer(); timer.start(); const elapsed = timer.elapsed(); ``` ``` -------------------------------- ### Start Jasmine Server on a Different Port Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/python.md Start the Jasmine server on a custom port by using the -p flag followed by the desired port number. ```sh jasmine server -p 1337 ``` -------------------------------- ### Regenerate Tutorials Source: https://github.com/jasmine/jasmine.github.io/blob/master/README.md Regenerates tutorial files using the locco.js script. Run this after making changes to tutorial source files. ```bash node locco.js ``` -------------------------------- ### HtmlReporterV2 Constructor Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.2/HtmlReporterV2.html Initializes a new instance of the HtmlReporterV2 class. It takes an options object for configuration. ```APIDOC ## HtmlReporterV2(options) ### Description Displays results and allows re-running individual specs and suites. ### Constructor #### new HtmlReporterV2(options) ##### Parameters: Name | Type | Description ---|---|--- `options` | Options object | Options object Since: * 6.0.0 Implements: * [Reporter](Reporter.html) ##### Example ```javascript const env = jasmine.getEnv(); const urls = new jasmine.HtmlReporterV2Urls(); const reporter = new jasmine.HtmlReporterV2({ env, urls, // container is optional and defaults to document.body. container: someElement }); ``` ``` -------------------------------- ### Run Tests (NPM) Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_node.md Execute your test suite using the `test` script defined in your `package.json` with NPM. ```shell $ npm test ``` -------------------------------- ### Mocking a GET Request with Jasmine Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/mocking_ajax.md Use `spyOn` to mock the `$.ajax` method and return a predefined response for GET requests. This is useful for testing components that fetch data. ```javascript describe("MyModule", function() { it("should fetch data correctly", function() { spyOn($, "ajax").and.callFake(function(options) { expect(options.type).toBe("GET"); expect(options.url).toBe("/data"); return { done: function(callback) { callback({ message: "success" }); } }; }); var module = new MyModule(); module.fetchData(); expect($.ajax).toHaveBeenCalled(); }); }); ``` -------------------------------- ### initialize() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.2/HtmlReporter.html Initializes the reporter. This method should be called before Env#execute. ```APIDOC ## initialize() ### Description Initializes the reporter. Should be called before [`Env#execute`](Env.html#execute). ### Method initialize ``` -------------------------------- ### configFromCurrentUrl() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/HtmlReporterV2Urls.html Creates a [`Configuration`](Configuration.html) from the current page's URL. Supported query string parameters include all those set by [`HtmlReporterV2`](HtmlReporterV2.html) as well as spec=partialPath, which filters out specs whose paths don't contain partialPath. ```APIDOC ## configFromCurrentUrl() ### Description Creates a [`Configuration`](Configuration.html) from the current page's URL. Supported query string parameters include all those set by [`HtmlReporterV2`](HtmlReporterV2.html) as well as spec=partialPath, which filters out specs whose paths don't contain partialPath. ### Method `configFromCurrentUrl()` ### Parameters None ### Returns Type: [`Configuration`](Configuration.html) ### Example ```javascript const urls = new jasmine.HtmlReporterV2Urls(); env.configure(urls.configFromCurrentUrl()); ``` ``` -------------------------------- ### Initialize Jasmine with Yarn Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_node.md Initialize Jasmine for your project using Yarn. ```shell $ yarn run jasmine init ``` -------------------------------- ### Basic Spy Setup Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/your_first_suite.md Initialize a spy on an object's method using `spyOn`. This spy will track calls and arguments. Spies are automatically cleaned up after each spec. ```javascript describe("A spy", function() { let foo; let bar = null; beforeEach(function() { foo = { setBar: function (value) { bar = value; } }; spyOn(foo, 'setBar'); foo.setBar(123); foo.setBar(456, 'another param'); }); ``` -------------------------------- ### specs() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/jsApiReporter.html Get all spec results. ```APIDOC ## specs() ### Description Get all spec results. ### Method jsApiReporter.specs() ### Returns Type Array.<[SpecDoneEvent](global.html#SpecDoneEvent)> ``` -------------------------------- ### status() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/jsApiReporter.html Get the current status for the Jasmine environment. ```APIDOC ## status() ### Description Get the current status for the Jasmine environment. ### Method jsApiReporter.status() ### Returns One of `loaded`, `started`, or `done` Type String ``` -------------------------------- ### Timer.elapsed() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/Timer.html Retrieves the time elapsed since the timer was started. ```APIDOC ## elapsed() ### Description Determines the time since the timer was started. ### Method `elapsed()` ### Returns - **number**: Elapsed time in milliseconds, or NaN if the timer has not been started. ``` -------------------------------- ### Webpack Configuration Differences for Testing Source: https://github.com/jasmine/jasmine.github.io/blob/master/_tutorials/react_with_browser.md Highlights the key differences between a main Webpack configuration and a test-specific configuration, focusing on entry points, output filename, and plugin usage. ```diff -const HtmlWebpackPlugin = require("html-webpack-plugin"); const path = require("path"); +const glob = require("glob"); module.exports = { - entry: "./src/index.js", + entry: glob.sync("spec/**/*Spec.js?(x)"), output: { - filename: "bundle.[hash].js", + filename: "test.js", path: path.resolve(__dirname, "dist"), }, - plugins: [ - new HtmlWebpackPlugin({ - template: "./src/index.html", - }), - ], + plugins: [], resolve: { modules: [__dirname, "src", "node_modules"], extensions: ["*", ".js", ".jsx", ".tsx", ".ts"], ``` ``` -------------------------------- ### suites() Source: https://github.com/jasmine/jasmine.github.io/blob/master/_api/6.1/jsApiReporter.html Get all of the suites in a single object, with their `id` as the key. ```APIDOC ## suites() ### Description Get all of the suites in a single object, with their `id` as the key. ### Method jsApiReporter.suites() ### Returns Map of suite id to `SuiteResult` Type Object ``` -------------------------------- ### Specify Custom Reporter Source: https://github.com/jasmine/jasmine.github.io/blob/master/setup/nodejs.md Install and use a custom reporter by providing its module path to the `--reporter` option. The module's default export must be a reporter constructor. ```sh npm i --save-dev jasmine-ts-console-reporter npx jasmine --reporter=jasmine-ts-console-reporter ``` -------------------------------- ### configureDefaultReporter(options) Source: https://github.com/jasmine/jasmine.github.io/blob/master/_npm-api/6.1/Runner.html Configures the default reporter that is installed if no other reporter is specified. ```APIDOC ## configureDefaultReporter(options) Configures the default reporter that is installed if no other reporter is specified. ### Parameters: Name | Type | Description --- | --- | --- `options` | ConsoleReporterOptions | ```