Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xdescribe vs fdescribe in jasmine

  • fdescribe - Execute if the spec.ts file is defined with fdescribed
  • xdescribe - Never execute if spec.ts file is defined with xdescribed

Is my understand is correct? and what about if am defined both xdescribe and fdescribe in two separate spec.ts file?

like image 730
Ramesh Rajendran Avatar asked Feb 12 '18 05:02

Ramesh Rajendran


People also ask

What is Xdescribe in Jasmine?

xdescribe: FunctionLike describe , but instructs the test runner to exclude this group of test cases from execution. This is useful for debugging, or for excluding broken tests until they can be fixed. See http://jasmine.github.io/ for more details.

What is Fdescribe in angular testing?

fdescribe: FunctionLike describe , but instructs the test runner to only run the test cases in this group. This is useful for debugging.

Why do we use Karma and Jasmine?

Jasmine is a behavior-driven development framework for testing JavaScript code that plays very well with Karma. Similar to Karma, it's also the recommended testing framework within the Angular documentation as it's setup for you with the Angular CLI. Jasmine is also dependency free and doesn't require a DOM.


1 Answers

  • fdescribe - focused describe. If it exists, jasmine will run only fdescribe spec and ignore other type of describe (describe and xdescribe).
  • xdescribe - disabled describe. It will never be executed.

Some scenarios to gain more understanding:

Scenario 1 - describe only

describe('test1', ..)

describe('test2', ..)

describe('test3', ..)

// Specs executed:
// test1
// test2
// test3

Scenario 2 - single fdescribe

fdescribe('test1', ..)

describe('test2', ..)

describe('test3', ..)

// Specs executed:
// test1

Scenario 3 - multiple fdescribe

fdescribe('test1', ..)

fdescribe('test2', ..)

describe('test3', ..)

// Specs executed:
// test1
// test2

Scenario 4 - single xdescribe

xdescribe('test1', ..)

describe('test2', ..)

describe('test3', ..)

// Specs executed:
// test2
// test3

Scenario 4 - multiple xdescribe

xdescribe('test1', ..)

xdescribe('test2', ..)

describe('test3', ..)

// Specs executed:
// test3

Scenario 5 - fdescribe and xdescribe exists

fdescribe('test1', ..)

xdescribe('test2', ..)

describe('test3', ..)

// Specs executed:
// test1

Beside those two, Jasmine also has fit and xit with same rules.

Interestingly, Jasmine 3 will show an error when running the test if fdescribe spec exists to prevent users from inadvertently disabled other specs.

The error message:

Incomplete: fit() or fdescribe() was found

Reference:

  • https://jasmine.github.io/api/3.5/global.html#fdescribe
  • https://jasmine.github.io/api/3.5/global.html#xdescribe
like image 65
deerawan Avatar answered Sep 29 '22 11:09

deerawan