Testing DOM manipulating in Jasmine test

前端 未结 3 1780
别那么骄傲
别那么骄傲 2020-12-06 16:12

I\'m creating a js widget and first part is to add script width javascript, something like this (example from google analytics):

(function() {
    var ga = d         


        
3条回答
  •  星月不相逢
    2020-12-06 16:56

    For setting up HTML fixtures in my specs, I wrote jasmine-fixture. With it, you can do stuff like this:

    var $foo, $input;
    beforeEach(function(){
      $foo = affix('.foo');
        # appends to the DOM 
    $input = $foo.affix('input[id="name"][value="Jim"]'); # appends beneath the .foo div

    And afterEach, it'll clean up after you.

    For expectations about the state of the DOM, I use jasmine-jquery. It offers a ton of matchers like the one below:

    it('is named Jim', function(){
      expect($input).toHaveValue("Jim");
    });
    

提交回复
热议问题