2

Im writing tests for the integration of a cropping tool in our angular app.

How would i mock an image file object based on a src or a local file i require?

Im using Karma, Mocha, Chai & Sinon - and this is how far iv'd gotten

describe('cropping tool', function() {
    var scope;
    var $compile;
    var $rootScope;
    var $templateCache;

    beforeEach(function() {
        module(
            'app',
            'modules/croptool/croptool.html',
            'modules/croptool/croptool.test.html'
        );

        angular.mock.module('ngMockE2E');

        inject(function(_$compile_, _$rootScope_, _$templateCache_) {
            $compile = _$compile_;
            $rootScope = _$rootScope_;
            $templateCache = _$templateCache_;
        });

        scope = $rootScope;
    });

    it('should validate that it loads the image into the cropper', function() {
        var template = $templateCache.get('modules/croptool/croptool.test.html');
        var element = angular.element(template);

        var directiveElem = getCompiledElement(element);
        var vm = element.isolateScope();

        // Expect the predefined value

        // Click the toggle button
    });

    // Helper function
    function getCompiledElement(template) {
        var compiledDirective = $compile(angular.element(template))(scope);
        scope.$digest();
        return compiledDirective;
    }

    function ae(element) {
        return angular.element(element);
    }
});
Simon Dragsbæk
  • 2,367
  • 3
  • 30
  • 53

0 Answers0