I had a strange case where none of the other answers here worked for me but then I remembered how I had created the file.
I had tried to be clever and used the following command
mkdir __tests__ && touch "${_}/index.test.js
The shell prompted me to complete the double quote and that was fine. I was able to load the file in IntelliJ Idea, but I was very confused as to why it was not getting javascript syntax highlighting. I tried to change the file association, but no luck.
Then I thought I would just delete the file and try to re-create it. When I typed the rm command I hit tab to autocomplete the file path and saw my problem:
rm __tests__/index.test.js$'\n'
Because I had hit enter before completing the double-quote in the command to create the file, the file was named index.test.js\n. IntelliJ Idea was happy to open the file and displayed it as index.test.js, but the extension was .js\n, not simply .js, hence it did not recognise the file as a .js file.
A rename would likely have worked, but I just deleted it and re-created it, this time without the \n at the end.