Skip to content

Instantly share code, notes, and snippets.

@rogeliog
Created December 7, 2016 18:36
Show Gist options
  • Save rogeliog/f234187043666b8b52d20621ecf7883a to your computer and use it in GitHub Desktop.
Save rogeliog/f234187043666b8b52d20621ecf7883a to your computer and use it in GitHub Desktop.
files not having a JS extension + files with no extension at all
const r = new RegExp('^(?!.*\.js$).*$');
it('Does not matches .js files', () => {
expect(r.test('dir/myFile.js')).toBeFalsy();
expect(r.test('dir.ext/myFile.js')).toBeFalsy();
expect(r.test('myFile.js')).toBeFalsy();
})
it('Matchs other extensions', () => {
expect(r.test('dir.something/myFile.other')).toBeTruthy();
expect(r.test('myFile.other')).toBeTruthy();
expect(r.test('myFile.jspy')).toBeTruthy();
expect(r.test('myFile.jsx')).toBeTruthy();
expect(r.test('myFile.py')).toBeTruthy();
// It fails for this case
// expect(r.test('myFile.foojs')).toBeTruthy();
})
it('Matches files with no extension', () => {
expect(r.test('dir/myFile')).toBeTruthy();
expect(r.test('myFile')).toBeTruthy();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment