var carto = require('../../../../../src/api/v4');

describe('api/v4/style/cartocss', function () {
  var cartoCSS;

  beforeEach(function () {
    cartoCSS = new carto.style.CartoCSS('#layer { marker-with:10; }');
  });

  describe('constructor', function () {
    it('should return an object', function () {
      expect(cartoCSS).toBeDefined();
    });

    it('should throw an error if cartoCSS is not provided', function () {
      expect(function () {
        new carto.style.CartoCSS(); // eslint-disable-line
      }).toThrowError('cartoCSS is required.');
    });

    it('should throw an error if cartoCSS is empty', function () {
      expect(function () {
        new carto.style.CartoCSS(''); // eslint-disable-line
      }).toThrowError('cartoCSS is required.');
    });

    it('should throw an error if cartoCSS is not a valid string', function () {
      expect(function () {
        new carto.style.CartoCSS(3333); // eslint-disable-line
      }).toThrowError('cartoCSS must be a string.');
    });
  });
});

@@ -44,16 +44,17 @@
 /v4');%0A%0A
+f
 describe
@@ -1015,13 +1015,682 @@
 );%0A  %7D);
+%0A%0A  describe('errors', function () %7B%0A    it('should trigger a CartoError when the style is not valid', function (done) %7B%0A      var client = new carto.Client(%7B%0A        apiKey: '84fdbd587e4a942510270a48e843b4c1baa11e18',%0A        username: 'cartojs-test'%0A      %7D);%0A      var source = carto.source.Dataset('ne_10m_populated_places_simple');%0A      var invalidCartoCSS = new carto.style.CartoCSS('#layer %7B invalid-property: 10; %7D');%0A%0A      invalidCartoCSS.on('error', function (cartoError) %7B%0A        expect(cartoError.message).toEqual('');%0A        done();%0A      %7D);%0A      var layer = new carto.layer.Layer(source, invalidCartoCSS);%0A      client.addLayer(layer);%0A    %7D);%0A  %7D);
 %0A%7D);%0A

Add test for cartoCSS errors