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

ParseError: Colon is expected (svelte with scss style) #89

Open
wadehrarshpreet opened this issue Nov 23, 2021 · 1 comment
Open

ParseError: Colon is expected (svelte with scss style) #89

wadehrarshpreet opened this issue Nov 23, 2021 · 1 comment
Labels
question Further information is requested

Comments

@wadehrarshpreet
Copy link

I am trying to write a test for the component which is using scss as default styling. But test is throwing error that its not able to understand scss

myComponent.svelte

<div>Hello <span>world</span></div>
<style>
div {
 padding: 20px;
 span {
  font-weight: bold;
 }
}
</style>

Test File

// mycomponent.test.js
import { render } from '@testing-library/svelte';
import MyComponent from './MyComponent.svelte';
...
const { component } = render(MyComponent, {});
...

Jest Config

module.exports = {
  transform: {
    '^.+\\.js$': 'babel-jest',
    '^.+\\.svelte$': ['svelte-jester', { preprocess: true, debug: true }],
  },
  moduleFileExtensions: ['js', 'svelte'],
  roots: ['<rootDir>/app/modules'],
  modulePaths: ['<rootDir>/app/modules'],
  moduleDirectories: ['node_modules', 'app/modules'],
  setupFilesAfterEnv: [
    '<rootDir>/app/modules/tests/setupTest.js',
    '@testing-library/jest-dom/extend-expect',
  ],
  clearMocks: true, // Automatically clear mock calls and instances before every test.
};

svelte.config.js

const preprocess = require('svelte-preprocess');

module.exports = {
  preprocess: preprocess({ defaults: { style: 'scss' } }),
};

Error Stack

Colon is expected
4:     padding: 20px;
5: 
6:     span {
              ^
7:       font-weight: bold;
8:     }
ParseError: Colon is expected

      at error (node_modules/svelte/src/compiler/utils/error.ts:25:16)
      at Parser$1.error (node_modules/svelte/src/compiler/parse/index.ts:101:3)
      at Object.read_style [as read] (node_modules/svelte/src/compiler/parse/read/style.ts:31:11)
      at tag (node_modules/svelte/src/compiler/parse/state/tag.ts:189:27)
      at new Parser$1 (node_modules/svelte/src/compiler/parse/index.ts:53:12)
      at parse (node_modules/svelte/src/compiler/parse/index.ts:218:17)
      at Object.compile (node_modules/svelte/src/compiler/compile/index.ts:93:14)
      at compiler (node_modules/svelte-jester/dist/transformer.cjs:135:32)
      at Object.processSync [as process] (node_modules/svelte-jester/dist/transformer.cjs:111:12)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:464:35)
@sebastianrothe
Copy link
Collaborator

Did you follow https://github.com/sveltejs/svelte-preprocess/blob/main/docs/preprocessing.md#scss-sass?

Do you have node-sass installed?

I also thought defaults were deprecated and now you have to set every language and style explicitly.

@sebastianrothe sebastianrothe added the question Further information is requested label Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants