Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem loading Karma-fixture using Jasmine #13

Closed
EduardoAC opened this issue Feb 8, 2016 · 2 comments
Closed

Problem loading Karma-fixture using Jasmine #13

EduardoAC opened this issue Feb 8, 2016 · 2 comments

Comments

@EduardoAC
Copy link

Hi

I was looking for a way to use my complex JSON file to test my responses then I found this karma-fixture project. However, it doesn't work the installation process that you put in your README. I wonder someone can help me to find my mistake or the bug in the way is included.

$ grunt jshint:test
Running "jshint:test" (jshint) task

test/spec/controllers/main.js
  line 17  col 20  'fixture' is not defined.
  line 28  col 9   'fixture' is not defined.

Here is my Karma.conf.js file

module.exports = function(config) {
  'use strict';

  config.set({
    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,

    // base path, that will be used to resolve files and exclude
    basePath: '../',

    preprocessors: {
      "test/json/*.json"   : ["json_fixtures"]
    },

    jsonFixturesPreprocessor: {
      variableName: "__json__"
    },

    // testing framework to use (jasmine/mocha/qunit/...)
    // as well as any additional frameworks (requirejs/chai/sinon/...)
    frameworks: [
      "fixture",
      "jasmine" 
    ],

    // list of files / patterns to load in the browser
    files: [
      // bower:js
      ...
      // endbower
      "app/scripts/**/*.js",
      "test/mock/**/*.js",
      "test/spec/**/*.js",
      {
        pattern: 'test/json/*',
      }
    ],

    // list of files / patterns to exclude
    exclude: [
    ],

    // web server port
    port: 8080,
    ...
    browsers: [
      "PhantomJS"
    ],
    // Which plugins to enable
    plugins: [
      'karma-fixture',
      'karma-json-fixtures-preprocessor',
      "karma-phantomjs-launcher",
      "karma-jasmine"
    ],

    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false,

    colors: true,

    logLevel: config.LOG_INFO,
  });
};

and here is my test file

'use strict';

describe('Controller: MainCtrl', function () {
   ...
    // Initialize the controller and a mock scope
    beforeEach(inject(function (_$httpBackend_, _$controller_, $rootScope) {
        $httpBackend = _$httpBackend_;
        $controller = _$controller_;
        scope = $rootScope;
        jsonData = fixture.load('posts.json'); 
        $httpBackend.whenGET('test/json/posts.json')
            .respond(200,{data: jsonData}); 
        createController = function(){  
            return $controller('MainCtrl', { $scope: $rootScope });
        };
    }));

    afterEach(function () {
        $httpBackend.verifyNoOutstandingExpectation();
        $httpBackend.verifyNoOutstandingRequest();
        fixture.cleanup();
    });
    ...
@billtrik
Copy link
Owner

Hello @EduardoAC, i just did a clean install using the readme instructions and it works ok.
Admittedly i did not run Angular specs.

If you would be so kind as to try the following simple steps:

  1. rm -rf ./node_modules and then npm install (just to be sure)
  2. change logLevel option inside karma.conf.js to config.LOG_DEBUG and let us know of the output.

@EduardoAC
Copy link
Author

Hi @billtrik Great to hear from you. I did how you said but it doesn't work for me. I use yeoman angular to create my repository

npm install -g yo grunt-cli bower
npm install -g generator-angular
yo angular

I get it working using jasmine-jquery so I didn't do more research in this area. It seen I couldn't find the fixture class name. I tried too to change the order of the includes in case I did a mistake. I would like to do more research. It probably take some time because I'm not familiar with Coffee script.

On the other hand, I also get a error from "Before(function(){...});" so I changed for before each.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants