Context.For applications in population synthesis, libraries of theoretical stellar spectra are often considered an alternative to template libraries of observed spectra, because they allow a complete sampling of stellar parameters. Most of the attention in published theoretical spectral libraries has been devoted to the visual wavelength range.Aims.The goal of the present work is to explore the near-infrared range where few observed fully calibrated spectra and no theoretical libraries are available.Methods.We make a detailed comparison of theoretical spectra in the range 1.57–1.67 μm for spectral types from A to early M and for giant and dwarf stars, with observed stellar spectra at resolutions around 3000, which would be sufficient to disentangle the different groups of late-type stars. We selected the NeMo grids of stellar atmospheres to perform this comparison.Results.We first demonstrate that observed spectral flux distributions can be matched very well with theoretical ones for almost the entire parameter range covered by the NeMo grids at moderate resolution in the visual range. In the infrared range, although the overall shape of the observed flux distributions still matches reasonably well, the individual spectral features are reproduced by the theoretical spectra only for stars earlier than mid F type. For later spectral types the differences increase, and theoretical spectra of K type stars have systematically weaker line features than those found in observations. These discrepancies are traced back to stem primarily from incomplete data on neutral atomic lines, although some of them are also related to molecules.Conclusions.Libraries of theoretical spectra for A to early M type stars can be successfully used in the visual regions for population synthesis, but their application in the infrared is restricted to early and intermediate type stars. Improving atomic data in the near infrared is a key element in making the construction of reliable libraries of stellar spectra feasible in the infrared.