7

When running jasmine it only presents dot(.) for successful tests, and only verbose if the test fails.

//test.spec.js
describe('jasmine', ()=>{
  it('should show this text', () =>{
  });
})

My running command is: jasmine-node test.spec.js

The result:

.
Finished in 0.003 seconds
1 test, 1 assertion, 0 failures, 0 skipped

How to make jasmine display this test result like jasmine should show this text?

Sang
  • 4,049
  • 3
  • 37
  • 47
  • 1
    If it helps your search, you're asking how to configure or use a different **reporter** with jasmine. – stealththeninja Nov 11 '17 at 01:25
  • I realise that this does not answer your question directly, but [Mocha](https://mochajs.org/) does list passing tests for you, it maybe an alternative for you to try. – Jeremy Oct 10 '19 at 12:08

3 Answers3

5

Use the --verbose flag:

> jasmine-node test.spec.js --verbose

jasmine - 0 ms
    should show this test - 0 ms

Finished in 0.007 seconds
1 test, 1 assertion, 0 failures, 0 skipped

Note: jasmine-node doesn't seem to be actively maintained. The jasmine CLI supports tests run from the command line.

Although jasmine doesn't have a verbose flag, you can use a custom terminal reporter (example: jasmine-terminal-reporter). From jasmine's documentation, add a helper file to load the custom reporter and include the helper in your configuration file.

helpers/terminal-reporter.js

var Reporter = require('jasmine-terminal-reporter');
var reporter = new Reporter(options);

jasmine.addReporter(reporter);

spec/support/jasmine.json

{
  "spec_dir": "spec",
  "spec_files": [
    "**/*[sS]pec.js",
  ],
  "helpers": [
    "helpers/**/*.js"
  ],
  stopSpecOnExpectationFailure: false,
  random: false
}
stealththeninja
  • 3,576
  • 1
  • 26
  • 44
  • 1
    `--verbose` works for `jasmine-node` but not `jasmine`. Any solution for `jasmine`? – Sang Nov 11 '17 at 01:46
  • edited my answer to include a solution for `jasmine`, it allows setup of custom reporters. – stealththeninja Nov 11 '17 at 02:03
  • thank you for you answer. In jasmine docs, there is `var Jasmine = require('jasmine'); var jasmine = new Jasmine();`. Do you know where should I place these lines of code. `jasmine init` only creates `spec/support/jasmine.json`. There is not any `.js` file to put these lines – Sang Nov 11 '17 at 02:12
  • in your answer, you mentioned `helpers/terminal-reporter.js`. How can I let `jasmine` know and use this file, not others? – Sang Nov 11 '17 at 02:13
  • oh. I think that i figured thing out. `.js` file could be any file. The only need is to execute `node` with that file. There is no need for `jasmine` cli, but `jasmine` local node is required. Helper files path is defined in the config object. Thank you – Sang Nov 11 '17 at 02:22
  • jasmine-terminal-reporter seems also no more maintained. – zygimantus Sep 22 '19 at 05:05
  • I had to do `jasmine.getEnv().addReporter(reporter);` in Jasmine 3.7.0 – Daniel Flippance Apr 27 '21 at 23:39
0

I know this is a relatively old question but found something which worked for me

describe('Desc1',() => {
   
    afterEach(() => {
      const myReporter = {
        specDone: (result) => {
          console.log('Spec FullName: ' + result.fullName);
          console.log('Spec Result: ' + result.status);
        }
      };
      jasmine.getEnv().addReporter(myReporter);
    });
})

Credit for the solution : https://groups.google.com/g/jasmine-js/c/qqOk6Nh7m4c/m/Nyovy2EjAgAJ

Mushtaq Jameel
  • 7,053
  • 7
  • 33
  • 52
  • Works well, though you can paste the new reporter a setup.js helper rather than an aftereach (which might add it a bunch of times) – Loren Nov 08 '22 at 19:39
0

You can use jasmine-spec-reporter.

Just add at the top of your test file:

import { SpecReporter } from 'jasmine-spec-reporter';
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: 'pretty' } }));
btx
  • 1,972
  • 3
  • 24
  • 36